#主机:192.168.2.129(mini2) 既是php主机,也是数据库主机
#yum install -y php php-fpm php-mysql mariadb-server
[[email protected]~ localhost]#cd /etc/php-fpm.d [[email protected]-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 [[email protected]-fpm.d localhost]#systemctl start php-fpm [[email protected]-fpm.d localhost]#ss -ntl|grep "9000" LISTEN 0 128 *:9000 *:* [[email protected]-fpm.d localhost]#mkdir -pv /data/shop/html [[email protected] localhost]#vim /data/shop/html/index.php <?php phpinfo(); ?>
#代理Nginx主机:172.16.251.223(mini1主机名)
[[email protected]~ localhost]#cd /etc/nginx/conf.d/ [[email protected] 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 [[email protected]~ localhost]#systemctl start mariadb [[email protected]~ localhost]#systemctl restart php-fpm #添加了新模块 [[email protected]~ localhost]#ss -ntl |egrep "9000|3306" LISTEN 0 128 *:9000 *:* LISTEN 0 50 *:3306 [[email protected]~ localhost]#mysql MariaDB [(none)]> GRANT ALL ON mydb.* TO [email protected]'localhost' IDENTIFIED BY 'mypass'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> GRANT ALL ON mydb.* TO [email protected]'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 [[email protected]~ 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的内置测试页面 [[email protected] 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; } [[email protected] localhost]#nginx -t [[email protected] localhost]#nginx -s reload
#Nginx代理主机172.16.251.223配置缓存 [[email protected] localhost]#vi /etc/nginx/nginx.conf http { fastcgi_cache_path /data/cache/fcgi levels=2:1:1 keys_zone=fcgicache:10m max_size=1g
[[email protected] 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; [[email protected] localhost]#nginx -t [[email protected] localhost]#nginx -s reload
[[email protected] localhost]#cat /data/cache/ fcgi/ ngnix/ [[email protected] localhost]#cat /data/cache/fcgi/ 9e/ eb/ f1/ [[email protected] localhost]#cat /data/cache/fcgi/ 9e/ eb/ f1/ [[email protected] localhost]#cat /data/cache/fcgi/9e/3/7/f46b8508aa08a6f8670fb088b8a9739e default.conf