Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

860
Views
Nginx's fastcgi-php.conf snippet is missing

I'm attempting to serve PHP with nginx, i've followed this tutorial successfuly before but on a new server for some reason I get the following error:

 nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory) 

In fact, the whole snippets directory of the nginx installation is missing.

I've installed PHP with the following commands:
- sudo apt-get install -y php7.0-cli php7.0-cgi php-fpm php-mysql
- sudo systemctl restart php7.0-fpm

I've installed the most up to date nginx that is available - and yet the directory and file is still not present.

How can this be remedied?

Bonus: What could have caused this?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

TLDR:

Final version is:

location ~ \.php$ {
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    include fastcgi_params;                
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}

i think it depends on the Nginx version you are using.

For Nate's answer, nginx-full will install 1.10.3 for you.

I'm using Nginx 1.12.2 on Ubuntu 16.04, with this version, it doesn't have sites-enabled and sites-available with it; and it also has a different PHP CGI setup.

You can either use Ulad Kasach's solution, or start to use the new way.

Here's an official doc for how to do it: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

BTW, in above post, you should also replace fastcgi.conf with fastcgi_params.

And add one more line which is in default orignially:

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

These are all new changes with Nginx 1.12.2 :(

Final version is:

location ~ \.php$ {
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    include fastcgi_params;                
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
about 4 years ago · Santiago Trujillo Report

0

Ended up having to look at a previous, working, configurations file and replicating it manually. Simply made the snippets directory and added a fastcgi-php.conf file with the following content:

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

You'll also need to replace the last line, include fastcgi.conf; with include fastcgi_params;.

I would have recommended to create the file fastcgi.conf; if it was not literally the same file with the additional line fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; in the case of fastcgi.conf

about 4 years ago · Santiago Trujillo Report

0

Had me stumped for a moment too. You want to install the nginx-full package on ubuntu as opposed to just nginx. nginx-full contains the bits you were missing.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!