PHP with Nginx downloads instead of renders

I’m sure this is kind of a duplicate question, but I’ve tried googling this to no avail. I’m trying to make a site that will just run a php script on a button press. I’m trying to get php to work right, so I have an info.php file here:


Now, whenever I try to go to this file in my webpage: it just tries to download it instead of render it. I feel like I’ve tried everything under the sun to fix this, but I have no clue whats going wrong with it.

Here’s my default nginx conf:

    server {
    	listen 8000 default_server;
    	listen [::]:8000 default_server;
    	root /var/www/;
    	index index.php index.html index.htm index.nginx-debian.html;
      	location / {
        		try_files $uri $uri/ /index.html;
    	location ~ \.php$ {
        		try_files $uri =404;
        		include snippets/fastcgi-php.conf;
        		# With php5-cgi alone:
        		# With php5-fpm:
        		#fastcgi_split_path_info ^(.+\.php)(/.+)$;
        		fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        		#fastcgi_index index.php;
        		include fastcgi_params;
    	location ~ /\.ht {
            	deny all;

PHP Version:

php --version
PHP 7.0.33-0ubuntu0.16.04.16 (cli) ( NTS )

Nginx Version:

    $ nginx -v
    nginx version: nginx/1.10.3 (Ubuntu)

Ubuntu Version:

    Ubuntu 16.04.6 LTS

I appreciate any insight. I’ve already uninstalled and reinstalled php. I’m sure this is a repeat question, but I’ve looked over most of the other stackoverflow results, and nothing worked for me.

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

The configuration looks good actually. I could suggest a couple of things:

  • Make sure that the PHP-FPM service is up and running:
systemctl status php7.0-fpm.service
  • Make sure that the listen address is set to the socket file that you’ve specified in your Nginx config. You can do that by viewing the following file:

And search for the following line

listen = /run/php/php7.0-fpm.sock

If those things are all good, I would recommend clearing your browser’s cache and also checking your Nginx error log:

tail -100 /var/log/nginx/error.log

Regards, Bobby