# FastCGI sent in stderr: "Primary script unknown"

**Code:** `Primary script unknown` · **Category:** PHP · **Seen on:** PHP

Nginx passed a script path to PHP-FPM that PHP-FPM couldn’t find — usually a wrong SCRIPT_FILENAME or root.

## Meaning

Nginx builds SCRIPT_FILENAME from `$document_root$fastcgi_script_name`. If root is wrong, the file doesn’t exist, or PHP-FPM runs in a different filesystem (container), FPM answers “Primary script unknown” and the browser shows “File not found.”

## Common causes

- Missing/incorrect `fastcgi_param SCRIPT_FILENAME`
- Nginx root differs from where the files are
- PHP-FPM in a container with a different path
- open_basedir/chroot restrictions

## Quick fix

1. Add `fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`
2. Make root match the real path in both Nginx and PHP-FPM
3. Mount the same path in both containers

## Detailed fix by platform

### Nginx

1. `include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;`

## How to diagnose

1. **Path** — What SCRIPT_FILENAME does Nginx send?
2. **FPM view** — Does that path exist inside FPM?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/php-fpm-primary-script-unknown)
