3

It's a matter asked thousand times and since I hate write posts, I read and search for all possible documentation before get to the annoying part (for me) which is writing.

So I have Nginx & PHP-FPM up and running with CentOS 7.2. PHP-FPM is working with /var/run/php-fpm/php-fpm.sockproperly declared in www.conf:

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock

This is my mywebsite.conf:

server {
    listen   80;
    server_name  www.mywebsite.net;

    # 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_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Also I have cgi.fix_pathinfo=0 in php.ini.

I have restarted/reloaded Nginx and PHP-FPM services, restarted the whole server, and got nothing. I can't display .php files, they're just downloads.

What am I missing?

Thanks in advance.

2 Answers 2

2

Are there any other server blocks in Nginx configuration, especially with listen 80 default or default_server directives?
Also try to add access_log and error_log to Nginx configuration to find out are there any access to that server and are there any errors.

2
  • Yes, there's actually another server block: 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 { } }
    – Alain
    Nov 19, 2016 at 18:02
  • So it means that right now you have to use www.mywebsite.net name to access your site with php configured. For all other names even mywebsite.net you will access default section and simply download files as is. Simple solution would be remove default_server from default server block and use it on your www.mywebsite.net server block. But also I recommend you to put all server names here and place files on different document root, so there will be no chance to download source php files with any fake server name. Nov 20, 2016 at 9:20
0

sudo vim /etc/php-fpm.d/www.conf

DO NOT UNCOMMENT listen.mode = 0660

1
  • What are you saying? that the user should open /etc/php-fpm.d/www.conf in an editor, but change nothing?  That doesn’t make any sense. Mar 17, 2019 at 2:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .