您好,登錄后才能下訂單哦!
一、準備環境
1、系統版本
[root@Webserver01 ~]# cat /proc/version
Linux version 3.10.0-514.16.1.el7.x86_64
2、關防火墻
[root@Webserver01 ~]# systemctl disable firewalld
3、準備yum源
[root@Webserver01 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
或
[root@Webserver01 ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
4、安裝基礎工具
[root@Webserver01 ~]# yum install -y net-tools vim lrzsz tree screen lsof tcpdump nc nmap
5、關掉SELINUX
[root@Webserver01 ~]# vim /etc/sysconfig/selinux SELINUX=disabled
6、更新并重啟
[root@Webserver01 ~]# yum update -y && reboot
二、開始安裝LAMP組建
LAMP至少需要以下組建:
httpd (提供 Apache 主程序)
mysql (MySQL 客戶端程序)
mysql-server (MySQL 服務器程序)
php (PHP 主程序含給 apache 使用的模塊)
php-devel (PHP 的開發工具,這個與PHP 外掛的加速軟件有關)
php-mysql (提供給PHP 程序讀取 MySQL 資料庫的模塊)
可以用以下命令一次安裝;
[root@Webserver01 ~]# yum install httpd mysql mysql-server php php-mysql
為了看的更詳細,我們一個一個安裝
1、利用yum命令安裝Apache
[root@Webserver01 ~]# yum -y install httpd
啟動httpd并且設置為開機啟動
[root@Webserver01 ~]# systemctl start httpd.service [root@Webserver01 ~]# systemctl enable httpd.service
輸入網址,查看測試頁
2、安裝Mariadb
利用yum命令進行安裝,并且配置開機啟動同樣還是利用yum命令進行安裝,并且配置開機啟動
[root@Webserver01 ~]# yum -y install mariadb-server mariadb [root@Webserver01 ~]# systemctl start mariadb.service [root@Webserver01 ~]# systemctl enable mariadb.service
配置root密碼
[root@Webserver01 ~]# mysql_secure_installation 安裝過程中會有幾個選項,大家根據自己的需要進行配置就好了 Enter current password for root (enter for none):(輸入原始root密碼,若無enter) OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] (是否設置root密碼) New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! Remove anonymous users? [Y/n] (是否移除匿名用戶) ... Success! Disallow root login remotely? [Y/n] (是否禁止遠程root登陸) ... skipping. Remove test database and access to it? [Y/n] (是否刪除測試數據庫) Reload privilege tables now? [Y/n] (重新載入) ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
登錄數據庫測試一下
[root@Webserver01 ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 13 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> exit Bye
3、安裝PHP
[root@Webserver01 ~]# yum -y install php
安裝所需組件
[root@Webserver01 ~]# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
啟動服務并設置開機自動啟動
[root@Webserver01 ~]# systemctl start httpd.service [root@Webserver01 ~]# systemctl enable httpd.service
查看80端口和3306端口是否處于監聽狀態:
[root@Webserver01 ~]# netstat -ntlp
測試php是否正常工作
編輯/etc/httpd/conf/httpd.conf文件,在DirectoryIndex后面填寫index.php,定義默認主頁為index.php
[root@Webserver01 ~]# vim /etc/httpd/conf/httpd.conf
重載httpd配置文件
[root@Webserver01 ~]# systemctl reload httpd.service
[root@Webserver01 ~]# vim /var/www/html/index.php
制作默認主頁/var/www/html/index.php,編寫如下內容
<h2>This is new Web !</h2> <?php phpinfo(); ?>
重啟httpd服務
[root@Webserver01 ~]# systemctl restart httpd.service
好了,該驗證最后是否成功了
打開網址 http://x.x.x.x/info.php 進行查看
看到這個頁面,我們就可以收工了,LAMP環境搭建結束!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。