Ubuntu – Unable to get error stack trace or error log while using php-fpm + nginx on Ubuntu 14.04

14.04nginxPHP

I am using php-fpm 5.5.9 along with nginx 1.4.6 on my Ubuntu 14.04 machine. I have installed them using apt-get package manager. I am unable to get a stack trace of the error that my index.php script encounters in error log as well as on the browser. I searched and implemented a couple of solutions from stackoverflow and other articles but none of them worked for me. Here is my nginx conf along with my php-fpm conf file. Please help me out if I am doing any silly mistake.

Nginx Configuration:

location ~ \.php$ {
        # With php5-fpm:
                #try_files $uri =404;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_read_timeout 600;
        fastcgi_send_timeout 600;
        proxy_connect_timeout  600;
        proxy_send_timeout  600s;
        proxy_read_timeout  600s;
        fastcgi_pass 127.0.0.1:7777;
        fastcgi_index index.php;
    }

PHP-FPM Configuration:

error_log = /tmp/php5-fpm.log

PHP-FPM pool Configuration:

catch_workers_output = yes 
slowlog = /var/log/php-fpm/$pool.log.slow
listen = 127.0.0.1:7777

php_flag[display_errors] = On 
php_admin_value[error_log] = /tmp/fpm-php.www.log 
php_admin_flag[log_errors] = On

Thanks in advance.

Best Answer

Try to put in your site's configuration inside the server directive the following:

access_log  /var/log/nginx/your_site.log;

error_log   /var/log/nginx/your_site.log;

replace the your_site.log with the name of your virtualhost - domain name.

Full example:

php-fpm

/etc/php5/fpm/php-fpm.conf

[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
include=/etc/php5/fpm/pool.d/*.conf

/etc/php5/fpm/pool.d

[www]
user = www-data
group = www-data
pm = dynamic
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6

Virtual host

upstream php {
        server unix:/tmp/php-cgi.socket;
        server 127.0.0.1:9000;
}

server {
    listen   80; ## listen for ipv4; this line is default and implied

    root /srv/www/mysite;
    index index.php;

    server_name mysite.com www.mysite.com;

    access_log  /var/log/nginx/mysite_access.log;
    error_log   /var/log/nginx/mysite_error.log;

    location / {
         try_files $uri $uri/ /index.php?$args; 
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
              root /usr/share/nginx/www;
        }



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

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9$
        location ~ \.php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                 }
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
        access_log off;
                log_not_found off;
        }
}
Related Question