實驗一、構建NP
(一)實驗布置:兩臺虛擬機充當代理服務器和后端服務器,一臺虛擬機充當客戶端。
(二)實驗目的:實現NP的搭建。
(三)實驗圖解:
(四)實驗步驟:
1、 在后端服務器安裝php-fpm文件,修改PHP-FPM的配置文件,vim
/etc/php-fpm.d/www.conf文件,如下:
listen = 127.0.0.1:9000 à listen
= 0.0.0.0:9000
listen.allowed_clients = 127.0.0.1à ;listen.allowed_clients
= 127.0.0.1
user = apache à user = nginx
group = apacheà group =
nginx
pm.status_path = / statusà pm.status_path = /pm_status 防止與其它沖突
ping.path = /pingà ping.path =
/pm_ping
;ping.response = pongà ping.response
= pong
2、 systemctl restart php-fpm重新啟動后端服務器的PHP-FPM程序
3、 mkdir -pv /data/shop/創建PHP存放目錄 vim /data/shop /index.php創建PHP文件
<?php
phpinfo();
?>
4、更改代理服務器的配置,vim /etc /nginx/conf.d/default.conf,把下面的注釋取消,并進行更改。
location ~ \.php$ {
root html;
fastcgi_pass 172.18.24.1:9000;
fastcgi_index index.php;
fastcgi_param
SCRIPT_FILENAME
/data/shop/$fastcgi_script_name;
include fastcgi_params;
}
5、 Nginx –t nginx –s reload
6、 測試:172.18.252.22/index.php
實驗二、構建NMP
(一)實驗布置:兩臺虛擬機充當代理服務器和后端服務器,一臺虛擬機充當客戶端。
(二)實驗目的:實現NP的搭建。
(三)實驗圖解:
(四)實驗步驟:
在構建好的NP基礎之上,繼續構建NMP,如下:
1、 在后端服務器上安裝yum
-y install php-mysql mariadb-server
2、 systemctl start mariadb
3、 systemctl restart php-fpm
4、 在mysql創建用戶,如下:
[root@localhost shop]#mysql
grant all on mydb.* to ‘myuser’@’localhost’ identified by
‘mypass’;
grant all on mydb.* to ‘myuser’@’127.0.0.1’ identified by
‘mypass’;
flush privileges;
exit;
5、 vim /data/shop/index.php
<?php
#phpinfo();
$conn =
mysql_connect(‘127.0.0.1′,’myuser’,’mypass’);
if ($conn)
echo “OK”;
else
echo “Failure”;
?>
6、 測試:172.18.252.22/index.php
原創文章,作者:chenxu@magedu.com,如若轉載,請注明出處:http://www.www58058.com/74878