1、準備環境php
一、系統版本html
[root@Webserver01 ~]# cat /proc/version
Linux version 3.10.0-514.16.1.el7.x86_64mysql
二、關防火牆linux
[root@Webserver01 ~]# systemctl disable firewalld
三、準備yum源
sql
[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
四、安裝基礎工具apache
[root@Webserver01 ~]# yum install -y net-tools vim lrzsz tree screen lsof tcpdump nc nmap
五、關掉SELINUX
vim
[root@Webserver01 ~]# vim /etc/sysconfig/selinux SELINUX=disabled
六、更新並重啓
bash
[root@Webserver01 ~]# yum update -y && reboot
2、開始安裝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
爲了看的更詳細,咱們一個一個安裝
一、利用yum命令安裝Apache
[root@Webserver01 ~]# yum -y install httpd
啓動httpd而且設置爲開機啓動
[root@Webserver01 ~]# systemctl start httpd.service [root@Webserver01 ~]# systemctl enable httpd.service
輸入網址,查看測試頁
二、安裝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
三、安裝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,編寫以下內容
<h1>This is new Web !</h1> <?php phpinfo(); ?>
重啓httpd服務
[root@Webserver01 ~]# systemctl restart httpd.service
好了,該驗證最後是否成功了
打開網址 http://x.x.x.x/info.php 進行查看
看到這個頁面,咱們就能夠收工了,LAMP環境搭建結束!