Report this

What is the reason for this report?

PHP files are DOWNLOADING instead of EXECUTING on nginx

Posted on July 18, 2014

Hi All,

It looks like Nginx can’t pass the php file to php-fpm.sock which results in download of php files instead of execution. Please help.

I set cgi.fix_pathinfo=0 inside /etc/php5/fpm/php.ini

I set listen = /var/run/php5-fpm.sock inside /etc/php5/fpm/pool.d/www.conf

My Droplet: Ubuntu 14.04 x64\Laravel 4\nginx\PHP-FPC

All packages seem to be latest - I got everything yesterday via apt-get update/upgrade.

//////////////////Start nginx config /etc/nginx/sites-available/default////////////

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

        root /var/www/laravel/public;
        index index.php index.html index.htm;

        server_name MY_SERVER_IP_IS_HERE;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

//////////////////End nginx config/////////////////



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

In my case, I forgot didn’t install PHP yet. Make sure you already installed it by typing php -v. If there is no version information about your PHP, then you should install it with:

  1. sudo apt update
  2. sudo apt install php-fpm

Hey Folks, just ran into this myself working with Wordpress. Try using:

location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

Referenced it from a working server, then ran a quick search for additional info. Chris_O from StackExchange recommends adding this to your php location block as well if you’re running php-fpm. – If you don’t already have it in your php-fpm.conf.

location ~ \.php {
        try_files $uri =404;

Cheers!

Kamal, thank you for your answer. I cleared my cache prior to posting… What solved it, is the REBOOT of the server!

Perhaps, this documentation (https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14-04) can be updated by adding “server reboot” if users can’t see the changes

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.