FastCGI stderr: PHP Notice: Undefined variable
When you see FastCGI sent in stderr in your Nginx error log, it is almost never an issue with Nginx itself. That message indicates that Nginx successfully passed the request to the PHP-FPM upstream server, but PHP executed some code and explicitly wrote a warning or notice to its standard error stream.
In this specific case, the logs show:PHP Notice: Undefined variable: confMsg in /usr/share/nginx/html/admin-interface/login.php on line 196
andPHP Notice: Undefined index: username in /usr/share/nginx/html/admin-interface/login.php on line 245.
These are runtime errors originating from your application logic, not a misconfiguration of the web server or the PHP handler. The fact that you moved this environment to Nginx while it worked elsewhere suggests the underlying code has a bug triggered by missing data, but the way you are seeing the error is specific to how Nginx and PHP-FPM handle logging.
Understanding the stderr Stream
To debug this effectively, you need to understand that Nginx treats the FastCGI response as binary data. By default, Nginx captures the standard output (stdout) of the PHP process and appends it to the main access log (if configured) or simply discards it depending on fastcgi_buffering. However, standard error (stderr) is treated differently.
When PHP generates a Notice or Warning, it writes to stderr. Nginx, by default, does not buffer this stream for later logging; it prints it immediately to the Nginx error log as soon as the upstream connection closes. This is why you see these messages prefixed with FastCGI sent in stderr.
The core issue here is that your PHP script (login.php) is attempting to access variables or array indices that do not exist at runtime.
Undefined variable: confMsg: A variable named$confMsghas not been defined before use.Undefined index: username: An array (likely$_GET['username']) is being accessed without checking if the key exists.
In a typical web hosting environment running Apache with mod_php, these notices might be suppressed or logged to a separate file configured in php.ini. With PHP-FPM behind Nginx, the behavior depends on your error_log directive in the PHP configuration and how Nginx is set up.
Fixing the Application Logic
The immediate fix lies in correcting the PHP code in /usr/share/nginx/html/admin-interface/login.php. You cannot configure Nginx to hide these errors without disabling error reporting globally, which is bad practice.
For the undefined variable $confMsg, you must either define it before use or initialize it:
// Option 1: Initialize if not set
$confMsg = isset($confMsg) ? $confMsg : '';
// Option 2: Check existence before use (if logic allows)
if (!empty($confMsg)) {
echo $confMsg;
}
For the undefined index username, you should always validate array access. The "undefined index" notice usually appears when using the $variable syntax on an unset key:
// Bad practice that triggers notices
$username = $_GET['username'];
// Safer approach
$username = isset($_GET['username']) ? $_GET['username'] : null;
Verifying PHP Error Logging Configuration
While fixing the code is the primary solution, you should also ensure your php.ini is configured to catch these issues. The source material mentions setting cgi.fix_pathinfo = 0, which is a common requirement when using PHP-FPM, but it does not control error reporting levels.
Ensure your php.ini has the following settings:
error_reporting = E_ALL
display_errors = Off
log_errors = On
error_log = /var/log/php-fpm/error.log
Setting display_errors = Off prevents raw errors from appearing in the browser, while log_errors = On ensures they go to a dedicated log file. You can then configure Nginx to forward these logs or monitor them separately. If you have multiple PHP-FPM pools, ensure the specific pool handling /admin-interface has catch_workers_output = on enabled in its pm.max_children or related directives, though standard setups usually handle this by default.
Conclusion
The error is not a result of missing Nginx directives like fastcgi_pass. Your configuration correctly points to the Unix socket. The FastCGI sent in stderr message is simply Nginx faithfully reporting that PHP wrote an error to its error stream. By initializing variables and checking array indices in your PHP code, you eliminate the noise from the logs and prevent potential downstream failures like 500 Internal Server Errors if those notices are elevated to warnings or errors later.