I have Nginx running and I’m trying to execute php scripts with it, I’m using the following tutorial as a guide:
I’ve done the same steps as the article but I have a problem; I get a 404 when I try to access my php file.
Here’s what I’ve tried: -Verified the directory permissions and ownerships: permissions set to 755 and owner is www-data with group www-data -Changed file name to index.php
I currently have 2 config files for each of my sites( mydomain.com and blog.mydomain.com) and I’m trying to run php scripts on mydomain.com. Here’s my config file for the site: <pre> server { listen 80;
server_name mydomain.com;
location / {
root /usr/share/nginx/html/mydomain.com;
index index.html index.htm index.php;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
} </pre> Is there another config file I should be checking? Or perhaps there is a different config since I’m running subdomains?
Thanks for your time.
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!
Are you seeing anything interesting in your Nginx error logs when you try to access the site? Run: <pre> tail /var/log/nginx/error.log </pre>
I’d also move <code>index.php</code> to the front in your location block: <pre> location / { root /usr/share/nginx/html/mydomain.com; index index.php index.html index.htm; } </pre>
I managed to get it working, the thing I was missing was including <code>location ~ .php$</code> inside the <code>location /</code> section. It ended up looking like this: <pre> location / { root /usr/share/nginx/html/mydomain.com; index index.html index.htm index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
</pre> Not sure if it’s standard to do it like this but it worked for me.
I am getting the same error when trying to load the info.php file and have been trying to solve it for hours but can’t seem to find a solution.
I installed LEMP with 16.04 but it seems hard to find why my php is not working.
My nginx sites-available file looks like this:
server {
listen 80;
listen [::]:80;
server_name website.com www.website.com;
location / {
root /var/www/website.com/html;
index index.html index.htm index.php index.nginx-debian.html;
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;
}
}
server {
listen 443;
ssl on;
# ssl_certificate
ssl_certificate /etc/nginx/cert_chain.crt;
# ssl_certificate_key
ssl_certificate_key /root/website.com.key;
server_name website.com website.com;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;
location / {
root /var/www/website.com/html;
index index.php index.html index.htm index.nginx-debian.html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.