Question

How to get PHP working after LEMP with 16.04 installation? I get error 404 even with info.php file.

I am getting the same error when trying to load the info.php file and have been trying to solve it for hours but can’t seem to find a solution.

I installed LEMP with 16.04 but it seems hard to find why my php is not working.

My nginx sites-available file looks like this:

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

    server_name website.com www.website.com;

    location / {
            root /var/www/website.com/html;
    index index.html index.htm index.php index.nginx-debian.html;
            try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
    deny all;


    }

}

server { listen 443; ssl on; # ssl_certificate ssl_certificate /etc/nginx/cert_chain.crt; # ssl_certificate_key ssl_certificate_key /root/website.com.key;

            server_name website.com website.com;
            access_log /var/log/nginx/nginx.vhost.access.log;
            error_log /var/log/nginx/nginx.vhost.error.log;
    location / {

            root /var/www/website.com/html;
    index index.php  index.html index.htm index.nginx-debian.html;

    }

location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; }

location ~ /\.ht {
    deny all;


            }

}

Subscribe
Share

Submit an 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.

I found and resolved the issue, I moved ``` root /var/www/website.com/html; index index.html index.htm index.php index.nginx-debian.html;


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

    root /var/www/example.com/html;
    index index.html index.htm index.php index.nginx-debian.html;

    server_name example.com www.example.com;

    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$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}



	}


	server {
    listen 443;
    ssl on;
            # ssl_certificate
            ssl_certificate /etc/nginx/cert_chain.crt;
            # ssl_certificate_key
            ssl_certificate_key /root/example.com.key;

             root /var/www/example.com/html;
    index index.html index.htm index.php index.nginx-debian.html;

            server_name example.com www.example.com;
            access_log /var/log/nginx/nginx.vhost.access.log;
            error_log /var/log/nginx/nginx.vhost.error.log;
    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$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
	}



}

This comment has been deleted

@demoskp

You need first to enable this site by creating a symbolic link for this site in sites-enabled directory

use this command to achieve this:

sudo ln -s /etc/nginx/sites-available/<sitename> /etc/nginx/sites-enabled/<sitename>

then restart nginx: sudo service nginx restart

Hope this helps