M BUZZ CRAZE NEWS
// general

PHP webpage downloads instead of opens in browser (nginx, php on debian10 server)

By Gabriel Cooper

I have a server running Debian 10. I have installed nginx (1.18.0) and php and php-fpm (7.4.28). Following this guide I was able to get html website with certification by certbot running. Then I wanted to use php to have menu on my website dynamic. When I go to the webpage it downloads instead of opening up.

My file tree is as follows: my webpage is stored in /var/www/dragallur, there is a file phpinfo.php with the following code (if I type it asks me to download the webpage):

<?php phpinfo(); ?>

In the directory /etc/nginx/sites-available there are two files, default and mywebsite, default has following contents:

server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html; server_name _; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ /.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;}}

And the file mywebsite:

server { server_name dragallur.xyz ; root /var/www/dragallur ; index index.php index.html index.htm index.nginx-debian.html ; location / { try_files $uri $uri/ =404 ; #try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ /.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; }
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot}
server {
if ($host = dragallur.xyz) { return 301
} # managed by Certbot listen 80 ; listen [::]:80 ; server_name dragallur.xyz ;
return 404; # managed by Certbot}

This issue seems to happen quite often to people. I have tried cleaning my cache, I have done countless changes to the two files above but I still get the same problem. There may be other key config files so just tell me and I will share the contents. After every change which I think might be useful I run the command

systemctl restart nginx
7 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy