Report this

What is the reason for this report?

PHP execution on nginx - files being downloaded instead

Posted on January 22, 2019

Hi,

I am attempting to execute PHP pages within my Nginx root directory, however despite many attempts to fix the issue they continue to be downloaded instead of executing. My nginx/sites-available/default file is:



server {
        listen 80 default_server;
        listen [::]:80 default_server;

         index index.php index.html index.htm index.nginx-debian.html;

         server_name _;

         # Serve up static content directly via nginx

         # Note: /var/www is a symlink to ~/qewd/www

         location / {
                  root /var/www;
                  try_files $uri $uri/ @qewd;

                  expires max;
                  access_log off;
          }

          location ~ \.php$ {
                  try_files $uri $uri/ ;
                  fastcgi_split_path_info ^(.+\.php)(/.+)$;
                  fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
                  access_log /var/www/php-access.log;
          }

No events are written to the php-access.log and on each occasion I attempt to access a php page in the root directory it is downloaded still. Nginx is correctly routing php to the location block as I have successfully tested 404 messages within the location block. The php7.2-fpm.sock file is within /var/run/php/php7.2-fpm.sock and the php7.2-fpm service is active.

I have tried changing the nginx.conf file for default_type from application/octet-stream to text/html and text/plain but this does not seem to have made a difference also

It seems as though nginx is not passing the php page to fpm but I’m not sure as to why or if I have missed something silly. My nginx user is www-data, which is also the owner of my php7.2-fpm.sock file.

Any help with this is greatly appreciated.

Thank you very much.

The developer cloud

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

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.