Nginx's fastcgi-php.conf snippet is missing

Nginx's fastcgi-php.conf snippet is missing

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Nginx's fastcgi-php.conf snippet is missing

When configuring a fresh server for PHP via FPM, you often encounter an nginx: [emerg] error indicating that /etc/nginx/snippets/fastcgi-php.conf cannot be found. This specific failure usually stems from a misunderstanding of how the LEMP stack packages handle configuration fragments on Debian-based systems like Ubuntu. The file isn't missing because it was deleted; it is missing because the package installation path has shifted or the directory structure relies on a different default location than what many online tutorials assume.

The error message open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory) explicitly tells us that Nginx expects this file at an absolute path. In the context of a standard LEMP stack installation using apt-get, the fastcgi-php.conf snippet is typically located in /etc/nginx/snippets/. However, if you are following a tutorial from 2016 or earlier, such as the DigitalOcean guide referenced in recent troubleshooting attempts, you may be relying on assumptions that no longer hold true for updated package repositories.

The root cause often lies in the version of Nginx and how it was installed. On modern Ubuntu releases (18.04 and later), the nginx package itself does not always include the /etc/nginx/snippets/ directory by default if the configuration is minimal. More commonly, the file exists within the PHP-FPM module or a separate helper package, but the standard installation often places the necessary FastCGI parameters in /etc/php7.x/fpm/conf.d/.

To remediate this issue immediately without installing extra packages, you must verify the actual location of the configuration file. Run the following command to check if the file exists elsewhere:

find /etc -name "fastcgi-php.conf" 2>/dev/null

If the file is found in /etc/php7.0/fpm/conf.d/, you have two options. The first is to manually create a symlink, though this is generally discouraged as it couples Nginx configuration to PHP package updates. The second, and preferred approach, is to recreate the necessary fastcgi_params block directly in your main site configuration or a dedicated include file.

You can extract the required parameters by checking the default PHP FPM config:

grep -A 20 "fastcgi_param" /etc/php7.0/fpm/conf.d/default-fpm.conf | head -n 25

Once you have the parameters, create the directory and file if they are absent:

sudo mkdir -p /etc/nginx/snippets
sudo touch /etc/nginx/snippets/fastcgi-php.conf

Then populate it with the standard FastCGI parameters. Note that on newer PHP versions (7.4+), the fastcgi_param directives might differ slightly, so ensure compatibility:

# /etc/nginx/snippets/fastcgi-php.conf
fastcgi_split_path_info ^(.+\.php)(/.+)$;
set $FASTCGI_PARAMS "";
include fastcgi_params;

Alternatively, and more robustly, simply include the standard fastcgi_params file directly in your Nginx site configuration:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi.conf;
    fastcgi_pass unix:/run/php7.0-fpm.sock;
}

This approach avoids the dependency on the snippets directory entirely, making your configuration more portable across different Nginx package versions. If you must keep the snippet structure, ensure that the PHP-FPM module installed via apt-get actually placed the file there. Some minimal installations omit the snippets directory to reduce attack surface or disk usage.

The bonus question of what caused this is often related to OS updates. When upgrading an older Ubuntu version (e.g., 16.04) to a newer one (e.g., 20.04), the package definitions change. The fastcgi-php.conf might have been moved to /etc/nginx/fastcgi_params or removed from the snippet directory altogether in favor of inline configuration. Always verify your Nginx version:

nginx -V

If you are using a specific Nginx module or a custom build, the default Debian/Ubuntu package paths will not apply. In those cases, inspecting the package contents with dpkg -L nginx or apt list --installed can reveal exactly where the configuration files are expected to reside.

For developers building production environments, relying on absolute paths hardcoded in tutorials is risky. Instead of assuming /etc/nginx/snippets/fastcgi-php.conf exists, check for its presence and fall back to including fastcgi_params directly from the PHP configuration directory or the main Nginx config. This practice ensures your web server remains functional regardless of minor package updates.

If you are deploying a Laravel application, this path is just as critical. While Laravel handles the PHP logic, the underlying Nginx configuration must correctly route .php files to the FPM socket. A missing or misconfigured fastcgi-php.conf snippet will result in 502 Bad Gateway errors before your application code ever executes. Ensuring the FastCGI parameters are correctly loaded is a prerequisite for any PHP-based stack, whether simple scripts or complex frameworks like Laravel.

Our network