1.安装PHP
yum -y install php php-mysql php-fpm
2.在nginx.conf文件中增加对PHP的支持
vim /usr/local/nginx/conf/nginx.conf
按 i 等任意能进入编辑模式的键进入编辑模式,在server配置中新增index.php
location / {
root html;
index index.html index.htm index.php;
}
在上面继续新增以下配置
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
location ~ .*\.php(\/.*)*$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_index index.php;
}
按ESC键退出编辑模式,输入:wq保存并退出Vim编辑器
3. 重启php-fpm服务
systemctl restart php-fpm
4. 重启Nginx服务
/usr/local/nginx/sbin/nginx -s reload
5. 检查PHP安装
在Nginx的网站根目录下创建PHP文件phpinfo.php
echo “” > /usr/local/nginx/html/phpinfo.php
访问PHP页面。在浏览器地址栏输入ip/phpinfo.php