you should install PHP and change Nginx config file
first, install PHP follow line:
sudo apt install php7.2 php7.2fpm
and change Nginx config file like the following:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name server_domain_or_IP;
location / {
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;
}
}
manpreet
Best Answer
3 years ago
I have been trying for weeks to get Nginx, and php7.2 to work together. I want to write html files, with embeded php tags. php files work splendidly. HTML files work as well. but when I try to embed php into html, the source code is printed to the html source. I have tried a variety of settings in my default config file for nginx, as well as numerous tutorials. It appears I am missing something but I cannot figure out what. Messing with it, I go throught various stages of inoperability, but I cannot get the php embeded part to work.
Here is my /etc/nginx/sites-available/default page:
server { listen 80 default_server; listen [::]:80 default_server ipv6only=off; root /home/tinker/public_html; index index.html index.php index.htm; server_name 192.168.1.103; location / { try_files $uri $uri/ =404; autoindex on; } error_page 404 /404.html; #error_page 500 502 503 504 /404.html; location = /50x.html { } location ~ \.php$|\.html|\.htm { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_pass unix:/run/php/php7.2-fpm.sock; # # # fastcgi_index index.php; # #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # fastcgi_index index.php; # fastcgi_param PATH_INFO $fastcgi_path_info; # # fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }how can i fix this?