Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My nginx + fastcgi configuration downloads php files instead of executing them

Tags:

nginx

fastcgi

I'm using this configuration on a fresh install of php5-fpm and nginx on ubuntu 13.04:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
            try_files $uri $uri/ /index.html;
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            allow ::1;
            deny all;
    }

    error_page 404 /404.html;

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}

But, my web browser is seeing php as text instead of the executed results. Where should I look to troubleshoot?

like image 873
iRyanBell Avatar asked Jul 21 '13 22:07

iRyanBell


1 Answers

Your php code is being displayed directly because it's not being sent to the php engine, that means the location block is being matched and the php file is being served, but the php file isn't being captured by the php block, so your problem is in the php block.

In that block you have 2 fastcgi_pass, one with a port (9000) and the other to a unix socket, you can't have both together, but since you've tagged your question with fastcgi so I'll assume you are using fastcgi, try commenting this line

#fastcgi_pass unix:/var/run/php5-fpm.sock;
like image 123
Mohammad AbuShady Avatar answered Oct 21 '22 09:10

Mohammad AbuShady