新安装 nginx + phpfpm 导致 PHP 文件下载

新安装 nginx + phpfpm 导致 PHP 文件下载

我刚刚按照指南中的步骤安装了 Nginx 和 PHP-FPM这里。但是,测试 PHP 信息页面似乎正在下载,而不是显示在浏览器上。

配置如下:

php.ini

[root@localhost ~]# grep fix_pathinfo=  /etc/php.ini 
cgi.fix_pathinfo=0

/etc/php-fpm.d/www.conf(已修改的部分)

listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nobody
listen.group = nobody
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

/etc/nginx/fastcgi_params

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

运行文件存在:

[root@localhost ~]# file /var/run/php-fpm/php-fpm.sock 
/var/run/php-fpm/php-fpm.sock: socket

nginx 进程似乎已启动:

root      2438  0.0  0.6 327192 10056 ?        Ss   19:06   0:00 php-fpm: master process (/etc/php-fpm.conf)
nginx     2440  0.0  0.2 327192  4540 ?        S    19:06   0:00 php-fpm: pool www
nginx     2441  0.0  0.2 327192  4540 ?        S    19:06   0:00 php-fpm: pool www
nginx     2442  0.0  0.2 327192  4540 ?        S    19:06   0:00 php-fpm: pool www
nginx     2443  0.0  0.2 327192  4540 ?        S    19:06   0:00 php-fpm: pool www
nginx     2444  0.0  0.2 327192  4540 ?        S    19:06   0:00 php-fpm: pool www

然而,PHP 文件似乎正在下载而不是在浏览器上加载 - 这是一个简单的信息页面:

[root@localhost html]# pwd
/usr/share/nginx/html
[root@localhost html]# cat info.php 
<? phpinfo(); ?>
[root@localhost html]# ll info.php 
-rw-r--r--. 1 root root 17 Jul 27 19:01 info.php

为了进一步检查,SElinux 被设置为 Permissive,服务器也重新启动了,但这些步骤都不起作用。并且正常的 HTML 文件正在被提供,没有错误/usr/share/nginx/html

我在设置时是否遗漏了一些配置/参数/指令?

相关内容