问题原因:解决方法1,配置nginx。conf文件3,开放端口
问题在安装ngnix与相应的php服务后发现访问php文件是直接下载下来并没有解析。
原因:因为nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端nginx一般是把请求发fastcgi管理进程处理,fascgi管理进程选择cgi子进程处理结果并返回被nginx而PHP-FPM就是一个PHP FastCGI管理器简单来说php-fpm把nginx与php服务联系到一起。
解决方法
1,配置nginx。conf文件在server{中添加如下代码:php-fpm默认端口是9000
location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }
这样配置好后重新启动nginx服务。systemctl restart nginx
3,开放端口发现虽然不下载php文件了,但还是访问不了。是因为php-fpm服务没有安装好查看端口netstat -tunlp | grep 9000发现没有回显安装php fpm依次执行下面命令:
yum install php72w-fpm
systemctl start php-fpm.service #启动php
systemctl enable php-fpm.service#设置开机自启动
#其他命令
systemctl restart php-fpm.service #重新启动php-fpm服务
systemctl status php-fpm.service #查看启动php-fpm服务
这样便可以访问php网页了。