一、確保php-fpm已經啟動:
ps -A | grep php-fpm
如果沒有啟動,則啟動php-fpm:
/usr/local/sbin/php-fpm
查看是否啟動成功:
root@iZ25fm7iewtZ:/usr/local/etc# ps -ef | grep php-fpm root 3691 1 0 18:49 ? 00:00:00 php-fpm: master process (/usr/local/etc/php-fpm.conf) www-data 3692 3691 0 18:49 ? 00:00:00 php-fpm: pool www www-data 3693 3691 0 18:49 ? 00:00:00 php-fpm: pool www root 4982 29553 0 18:59 pts/1 00:00:00 grep --color=auto php-fpm root@iZ25fm7iewtZ:/usr/local/etc# netstat -tnl | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
修改nginx的配置文件,支持php文件的解析,找到location的添加位置,在后面添加下面這個location
location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; #以下方式也可以 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
重啟nginx
service nginx restart
進入web更目錄,編輯index.php
<?php echo "hello php !"
瀏覽器中輸入:localhost/index.php 即可