#主机:192.168.2.129(mini2)   既是php主机,也是数据库主机
#yum install -y php php-fpm php-mysql mariadb-server
[root@~ localhost]#cd /etc/php-fpm.d [root@php-fpm.d localhost]#vim www.conf listen = 0.0.0.0:9000 ;listen.allowed_clients = 127.0.0.1 user = nginx group = nginx pm.status_path = /pm_status ping.path = /pm_ping ping.response = pong [root@php-fpm.d localhost]#systemctl start php-fpm [root@php-fpm.d localhost]#ss -ntl|grep "9000" LISTEN 0 128 *:9000 *:* [root@php-fpm.d localhost]#mkdir -pv /data/shop/html [root@php-fpm.d localhost]#vim /data/shop/html/index.php <?php phpinfo(); ?>

 

#代理Nginx主机:172.16.251.223(mini1主机名)
[root@~ localhost]#cd /etc/nginx/conf.d/ [root@conf.d localhost]#vim default.conf location ~ \.php$ { root html; fastcgi_pass 192.168.2.129:9000; #php-fpm数据库的ip fastcgi_index index.php; #$fastcgi_script_name是请求的url;/data/shop是php-fpm下定义的URL fastcgi_param SCRIPT_FILENAME /data/shop/$fastcgi_script_name; include fastcgi_params; }

 

#在主机192.168.2.129上安装php-mysql 和mariadb-server
[root@~ localhost]#systemctl start mariadb
[root@~ localhost]#systemctl restart php-fpm       #添加了新模块
[root@~ localhost]#ss -ntl |egrep "9000|3306"
LISTEN     0      128          *:9000                     *:*                  
LISTEN     0      50           *:3306   
[root@~ localhost]#mysql
MariaDB [(none)]> GRANT ALL ON mydb.* TO myuser@'localhost' IDENTIFIED BY 'mypass'; 
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> GRANT ALL ON mydb.* TO myuser@'127.0.0.1' IDENTIFIED BY 'mypass'; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> EXIT;
Bye

[root@~ localhost]#vim /data/shop/index.php 
<?php
#判断数据库连接状态

$conn = mysql_connect('127.0.0.1','myuser','mypass');
  if ($conn)
    echo "OK";
  else
    echo "Failure";
phpinfo();

?>

 

 

 

#在主机172.16.251.223配置php-fpm的内置测试页面
[root@conf.d localhost]#vim default.conf
  location ~* ^/(pm_status|pm_ping)$ {
                include fastcgi_params;
                fastcgi_pass 192.168.2.129:9000;
                fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        }  
[root@conf.d localhost]#nginx -t
[root@conf.d localhost]#nginx -s reload
  

 

 

 

#Nginx代理主机172.16.251.223配置缓存
[root@conf.d localhost]#vi /etc/nginx/nginx.conf
http {
fastcgi_cache_path /data/cache/fcgi levels=2:1:1 keys_zone=fcgicache:10m max_size=1g
[root@conf.d localhost]#vim default.conf location ~ \.php$ { fastcgi_cache fcgicache; fastcgi_cache_key $request_uri; fastcgi_cache_valid 200 302 10m; fastcgi_cache_valid 301 20m; fastcgi_cache_valid any 1m; [root@conf.d localhost]#nginx -t [root@conf.d localhost]#nginx -s reload

 

 

[root@conf.d localhost]#cat /data/cache/
fcgi/  ngnix/ 
[root@conf.d localhost]#cat /data/cache/fcgi/
9e/ eb/ f1/ 
[root@conf.d localhost]#cat /data/cache/fcgi/
9e/ eb/ f1/ 
[root@conf.d localhost]#cat /data/cache/fcgi/9e/3/7/f46b8508aa08a6f8670fb088b8a9739e default.conf