nginx – Ngnix – FastCGI sent in stderr: "PHP message: PHP Notice: Undefined variable-ThrowExceptions

Exception or error:

I’ve installed an Ngnix server and configured it like:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #       proxy_pass;    
    # redirect server error pages to the static page /50x.html
    error_page 500 502 503 504 /50x.html;
    location = / {
      # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #       # With php5-cgi alone:
    #       fastcgi_pass;
    #       # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #       deny all;


I’m getting these errors (copied from my error.log) :

    *9 FastCGI sent in stderr: "PHP message: PHP Notice:  Undefined variable: confMsg in /usr/share/nginx/html/admin-interface/login.php on line 196" while reading upstream, client:, server: localhost, request: "GET /admin-interface/login.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost"

2015/12/16 00:27:37 [error] 952#0: *9 FastCGI sent in stderr: “PHP message: PHP Notice: Undefined index: username in /usr/share/nginx/html/admin-interface/login.php on line 245
PHP message: PHP Notice: Undefined index: username in /usr/share/nginx/html/admin-interface/login.php on line 249” while reading upstream, client:, server: localhost, request: “GET /admin-interface/login.php HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php5-fpm.sock:”, host: “localhost”

I’m trying to configure this environment using an Ngnix server, this environment does work using different hosting.
I did change the cgi.fix_pathinfo = 0 in my php.ini

What am i missing with my configuration?

How to solve:

It’s not an error, it’s a notice.

The script /usr/share/nginx/html/admin-interface/login.php is accessing the variable $confMsg which does not exist at that point.

You can either change the error reporting level in php.ini (which has impact on other scripts too and you don’t want to turn off notices..) or fix the wrong variable access in the script.

The second solution would be easier because you’d just had to initialize $confMsg = '';.


I’m sorry to say this question is so vague it’s hard to answer…
What is the problem??

As far as i can see from the error file, there is no problem here. Just PHP Notices.

Look at this:

error_page 500 502 503 504 /50x.html;
location = /50x.html {

Can’t you see anything wrong? You are including the / location into the error location, not logic my friend… Your php files under “/” will never be passed on to php5-fpm that way. Unless i understand nothing from what you are asking, do this;


location = /50x.html {

and downwards.

add this instead:

location ~ [^/]\.php(/|$) { #open location bracket

    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) { #open condition bracket
        return 404;
    } #close condition bracket

    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

} #close location bracket


sudo nginx -t # to test your config.

If there’s a problem, look for opening and closing brackets as this seem to be your nemesis (you are in the server block which you opened a bracket for – make sure you close it). If all pass;

sudo nginx -s reload

And please, next time you post code, take a second to remove all the junk comments. That’ll help you get answers or at least interrest to your question.

If all is good then, you might consider adding theses location configurations for a more robust/efficient server;

# send expire headers
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off; # optional
    log_not_found off; # optional
    expires max;

location = ^/favicon.ico {
    access_log off;
    log_not_found off;

# robots noise...
location = ^/robots.txt {
    log_not_found off;
    access_log off;
    allow all;

# block access to hidneen files (.htaccess per example)
location ~ /\. { access_log off; log_not_found off; deny all; }

if you don’t understand a setting, don’t add it. It would be like blindly putting fuel in your car without knowing what type it is.

Leave a Reply

Your email address will not be published. Required fields are marked *