skip to Main Content

currently I’m trying to run a php file on my nginx server. I downloaded all packages, changed the config file, but it is still not working. I can open my index.html, but when I open my php file it just downloads it.
enter image description here

enter image description here

enter image description here

My code of the config file:
server {
listen 80 default_server;

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

server_name test;

location / {

    try_files $uri $uri/ =404;
}
location ~ .php$ {
    try_files $uri $uri/ =404;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix: /var/run/php/php8.0-fpm.sock
}

}

Please help me.

2

Answers


  1. Try this I pulled from a working server

    server {
            listen 80;
            root /var/www/html;
            index index.php index.html index.htm;
            server_name 10.0.0.19;
     
            location / {
                try_files $uri $uri/ =404;
            }
     
            location ~ .php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
            }
    }
    

    I only changed the fpm and server name since well the server is using 7 and the server_name was the ip of the server…I put yours

    Login or Signup to reply.
  2. Your configuration file is invalid, and It may not applied. Try this and run sudo nginx -t && sudo systemctl restart nginx.

    server {
        listen 80 default_server;
    
        root /var/www/html;
        index index.html index.htm index.php index.nginx-debian.html;
    
        server_name test;
    
        location / {
            try_files $uri $uri/ =404;
        }
        location ~ .php$ {
            try_files $uri $uri/ =404;
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search