Nginx fastcgi-php.conf snippet is missing

I am trying to serve PHP using nginx, I followed this tutorial successfully, 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 entire snippets

nginx installation directory is missing.

I 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 have installed the most updated nginx available and still the directory and file are still missing.

How can this be fixed?

Bonus: what could have caused this?

+3


source to share


3 answers


I think it depends on the version of Nginx you are using.

To answer, Nate will nginx-full

install 1.10.3 for you.

I am using Nginx 1.12.2 on Ubuntu 16.04, with this version it doesn't have sites-enabled

and sites-available

; and it has a different PHP CGI setting as well.

You can use Ulad Kasach's solution or start using a new way.

Here is the official doc on how to do this: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

By the way, in the above entry, you must also replace fastcgi.conf

with fastcgi_params

.



And add one more line which is by default:

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

These are all new changes since Nginx 1.12.2 :(

Final version:

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;
}

      

+7


source


I groaned too. You want to install the package nginx-full

on ubuntu, not just nginx

. nginx-full

contains the bit you are missing.



+4


source


Ended up reviewing the previous, working, configuration file and manually replicating it. Just made a directory snippets

and added a file fastcgi-php.conf

with the following content:

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

# Check that the PHP  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 will also need to replace the last line include fastcgi.conf;

with include fastcgi_params;

.

I would recommend creating a file fastcgi.conf;

if it weren't literally the same file with an extra line fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

in casefastcgi.conf

+3


source







All Articles