my configuration file is virtually identical to step four of this tutorial here
here is what my code looks like as of configuration file
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name 128.199.226.219;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# try_files $uri =404;
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Heya,
In case anyone stumbles upon the question here is a summarized answer:
The issue you’re experiencing is due to the configuration for PHP files in your Nginx server block being commented out. The
location ~ \.php$
block is responsible for processing PHP files and passing them to a FastCGI process manager (like PHP-FPM), which executes the PHP scripts and returns the result to Nginx. If this block is commented out or missing, Nginx will treat PHP files as static files and try to download them, instead of processing them.To fix this, you’ll need to uncomment (remove the
#
at the beginning of) the lines related to PHP processing in your server block. Based on your posted configuration, the relevant block should look something like this:Also, please ensure that PHP-FPM is installed and running, and that the socket path in
fastcgi_pass
(currentlyunix:/var/run/php5-fpm.sock
) matches the one configured in your PHP-FPM configuration. If you’re using a different version of PHP, the socket path may be different (for example,unix:/var/run/php/ph8.0-fpm.sock
for PHP 8).Once you’ve made these changes, you can test your configuration with the command
sudo nginx -t
to make sure there are no syntax errors, and then reload or restart Nginx withsudo service nginx reload
orsudo service nginx restart
.Hi. I have the same issue and have spent some days trying to work out what is going wrong.
I have always used apache however this application needs to run on nginx.
(I would like to say that the Digital Ocean tutorials are exceptionally good!!!)
My Default file is as follows:
Default server configuration
server { listen 80 default_server; listen [::]:80 default_server;
root /usr/share/nginx/html;
location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:var/run/php/php7.0-fpm.sock; }
}
Virtual Host configuration for example.com
You can move that to a different file under sites-available/ and symlink that
to sites-enabled/ to enable it.
#server {
listen 80;
I have tried varying combinations of this without luck. Have tried with SSL without.
I am obviously missing something here.
Any assistance greatly appreciated.
Thank you
You are missing most of the php configuration in your nginx conf file. This (taken from the end of step 4 in that tutorial) is what you should have in place. Be sure to have the Location / block which tells nginx to use php-fpm to process .php files.