部署要求:(1)CentOS 7 httpd,php-fpm,mariadb三者分離於三台主機;
web主機:192.168.11.101 部署httpd服務;
fcgi主機:192.168.11.227 部署php-fpm服務;
mariadb主機:192.168.11.241 部署mariadb服務;
(2)一個虛擬主機用於提供phpMyAdmin;另一個虛擬主機用於提供wordpress;
部署過程:
一、為各主機安裝相關服務並啟動服務,此處為yum安裝。
1、在web主機上安裝httpd服務並啟動:
yum -y install httpd

2、在fcgi主機上安裝php-fpm和php-mysql並啟動服務;
yum -y install php-fpm php-mysql

3、在mariadb主機上安裝mariadb-server並啟動服務;
yum -y install mariadb-server

二、在web主機上配置httpd服務
1、編輯httpd配置文件,注釋中心主機,添加php識別:
注釋中心主機:

添加php識別:


2、查看httpd服務中fcgi模塊是否已加載:

3、配置虛擬主機並支持fcgi模塊:


其中192.168.11.227為fcgi主機IP地址;
3、創建各虛擬DocumentRoot目錄,檢測語法並重載服務:


4、在各虛擬主機DocumentRoot目錄下創建測試頁,測試httpd服務:
vim /www/mywp.com/index.html


vim /www/mypma.com/index.html


三、在fcgi主機上配置fpm服務
1、編輯fpm服務www.conf配置文件:

監聽本機9000端口:

其中192.168.11.227為本機IP地址;
配置允許請求的客戶的IP地址,即外部httpd主機IP地址:

其中192.168.11.101為web主機IP地址;
fpm配置發生變化需重啟fpm服務:systemctl restart php-fpm.service
2、創建session目錄,並確保運行php-fpm進程的用戶對此目錄有讀寫權限;

3、創建動態資源目錄,並創建測試頁面進行測試:
創建動態資源目錄:

分別在兩個目錄下創建測試頁面:
vim /www/mywp.com/test.php

vim /www/mypma.com/test.php

浏覽器測試:


四、在mariadb主機上配置mariadb服務
1、創建wordpress所需數據庫:

2、為wordpress和phpMyAdmin授權用戶:
授權:

查看、刷新權限生效:

3、在fcig主機動態資源目錄下編輯測試頁面,測試與mariadb服務是否連通:
分別在兩個動態資源目錄下編輯測試頁面:
vim /www/mywp.com/test.php

vim /www/mypma.com/test.php

浏覽器測試:


五、wordpress安裝
1、下載wordpress壓縮包至fcgi主機,並解壓至wordpress的動態目錄:

2、創建並編輯配置文件:


在httpd主機的wordpress虛擬主機的目錄下要有同樣的操作;
3、浏覽器測試:

注冊安裝,登錄即可進入!
六、phpMyAdmin安裝
1、下載phpMyAdmin壓縮包至fcgi主機,並解壓至phpMyAdmin的動態目錄:

2、創建並編輯配置文件:
創建配置文件:

生成隨機數,編輯配置文件:



在httpd主機的phpMyAdmin虛擬主機的目錄下要有同樣的操作;
3、同時需要安裝字符轉換包php-mbstring:
yum -y install php-mbstring

浏覽器測試:

使用授權用戶登錄:

至此,三機分離lamp部署完成!