I have nginx and php-fpm installed on Centos 7, when i try and go to a test php file it downloads it instead of running and rendering in the browser. All other html, image files etc display fine.
If this has been answered elsewhere on the site please excuse this post and I will delete, but all other posts I have seen are for Ubuntu and suggestions there do not work. I also tried temporarily disabling selinux and same thing.
In my /usr/share/nginx/html/ directory I have a php file with the phpinfo() function:
[root@www1 html]# ll /usr/share/nginx/html/
total 24
-rw-r--r--. 1 root root 3650 Oct 4 11:53 404.html
-rw-r--r--. 1 root root 3693 Oct 4 11:53 50x.html
-rw-r--r--. 1 root root 3700 Oct 4 11:53 index.html
-rw-r--r--. 1 root root 20 Jan 8 01:44 info.php
-rw-r--r--. 1 root root 368 Oct 4 11:53 nginx-logo.png
-rw-r--r--. 1 root root 2811 Oct 4 11:53 poweredby.png
My configs are below:
[root@www1 nginx]# cat /etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
pm = dynamic
[root@www1 nginx]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
[root@www1 nginx]# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name my_ip_here;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}