1

I was able to successfully access php files when I was only using http but now that I installed https, I cant access the page anymore instead I download the script.

This is my file at /etc/nginx/sites-avaliable/default

server{
root /media/world/web/dev;

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

server_name localhost  web.dev;

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

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/web.dev/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/web.dev/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

Tutorials that I followed

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04

https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx (Nginx - ubuntu 18.04)

The https is working, if I execute index.html it works fine.

Could anyone point to me on how I can debug this?

2 Answers 2

2

Your /etc/nginx/sites-avaliable/default file doesn't contain php configurations, or do you have another file in /etc/nginx/sites-avaliable/ with it, as mentioned in the DigitalOcean link? If not, it seems you might have accidentally removed the it while configuring SSL. Try adding the below before the Certbot configurations is the file:

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
3
  • Man you saved me :) I was going crazy to why this wasnt working. certbot removed this bit of the code when I installed it. THANK YOU!!!!
    – LukeDS
    Apr 8, 2019 at 10:12
  • @LukeDS all good buddy, am a SysAdmin :D
    – beginer
    Apr 9, 2019 at 0:30
  • Thank you so much!!!!!! how is this even possible? Sep 16, 2020 at 10:01
0

Nginx does not contain native PHP processing like some other web servers. So, before setup PHP configurations you'll need to install php-fpm package with the following command:

sudo apt install php-fpm

After then set up the rest of the configurations on your configuration file:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .