How to serve PHP files on Nginx

Опубликовано: 27 Октябрь 2024
на канале: Abstract programmer
1,558
22

Let's see how to use Nginx to host a PHP website and solve the problems:
Nginx 403 forbidden
PHP file downloaded instead of run

Nginx configuration file with PHP support:

server {
listen 80;
server_name your_server_domain_or_IP;

root /var/www/html;
index index.php index.html index.htm;

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.x-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}