EDIT:
I have done everything suggested in the duplicate answers and nothing works. Here is my PHP info:
This is a specific issue with nginx and stderr messages and is not a generic "how do I turn on PHP error reporting" issue.
While developing I'm getting blank pages in my browser whenever I create a fatal error in PHP with a typo or just my bad programming ;). It's super annoying for me to have to view the raw nginx error log file to see the fatal errors and find the line numbers where they are. I can't seem to find how to make nginx display PHP fatal errors in the browser. Here is the relevant part of my nginx config:
location #fpm {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_NAME index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $path_info;
}
Here's an example error that shows up in my error log and then results in a blank browser page:
2014/01/04 14:53:52 [error] 20082#0: *403 FastCGI sent in stderr:
"PHP message: PHP Fatal error: Cannot redeclare class ClassName in FilePath on line 356"
while reading response header from upstream, client: 192.168.1.10,
server: servername, request: "GET URLPATH HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "host",
referrer: "referer"
Here is my PHP-FPM conf:
http://pastebin.com/QkCTbBYj
And my PHP-FPM pool conf:
http://pastebin.com/TZfZ8d7G
And my PHP-FPM php.ini:
http://pastebin.com/RsXRxduf
I would love if anyone could shed some light on what I could do to get these errors to show up!
try setting catch_workers_output to yes in pool config:
; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = yes
if that doesn't work you might have this bug:
https://bugs.php.net/bug.php?id=61045
Related
I am setting up fastcgi on nginx. I sort of have it working. Inside my location block if i have factcgi_param SCRIPT_FILENAME /var/www/cgi-bin/hello.cgi; it works. However I don't want to hard code the link.
Setting fastcgi with the below configuration
factcgi_param SCRIPT_FILENAME /var/www/cgi-bin/$fastcgi_script_name;
I get the following error
cannot get script name are document_root and script_name or (script_file) set and is the script executable?
while reading response header upstream from upstream. client 127.0.0.1,
server _, request "get /cgi-bin/hello.cgi"
On the webpage I get 403 Forbidden
hello.cgi is executable and works when I hard code it.
My fastcgi_params
I installed nginx at centos7(VPS) I know this question are often asked here. I've been searching solution but my nginx get worse. so I post here.
when first time I tried open a php file broswer asked file download insted of display. I searched solution at web and adjust code. after that.
I can display "Welcome to nginx!" but when I tried to open index.php , I got "An error occurred." That what I made a file that
Could you teach me what is wrong my code please?
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
And this is my log
2019/04/14 03:33:51 [error] 3445#3445: *10 connect() failed
(111: Connection refused) while connecting to upstream,
client: 140.xxx.xxx.x, server: localhost, request:
"GET /index.php HTTP/1.1", upstream:
"fastcgi://127.0.0.1:9000", host: "xxx.xxx.xxx.x"
I have created docker image, which includes the Debian packages nginx-full, php7.0, php7.0-fpm, php-zmq and application code written in PHP.
When I am trying to invoke the application from a browser (basically calling zeroMQ), I receive a 502 bad gateway error. How can I find out whether it is a server or a code problem?
Tried changing the permission to the socket file and
not able to print the PATH_INFO variable.
Nginx log:
157#157: *622 recv() failed (104: Connection reset by peer) while reading response header from upstream,
PHP-FPM log:
[02-Apr-2018 16:05:26] WARNING: [pool www] child 197 exited on signal 11 (SIGSEGV) after 79.435089 seconds from start
[02-Apr-2018 16:05:26] NOTICE: [pool www] child 203 started
nginx configuration:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi_params;
}
PHP-FPM configuration :
user = www-data
group = www-data
//tried 127.0.0.1:900 but did not work
listen = /run/php/php7.0-fpm.sock
After receiving the error, when I do php-fpm reload, the error goes off. But then will happen again.
It is a known bug, try using this update:
Dockerfile
My actual problem was that I wanted to make my "site.com/blog/index.php" direct to "/srvX/www/blog/caller/index.php". Althought it would be very straightforward to direct to "/srv/www/blog/index.php" using "root /srv/www/", that's not what I wanted. I discovered "alias", and it seem to do what I want.
1)First try :
server {
listen 80;
server_name _;
root /srv/www/blog/pages;
index index.php;
location /blog {
alias /srv/www/blog/caller;
}
}
There trying site.com/blog get me a 404 not found, and nothing pop into /var/log/nginx/error.log
1)Second try to know what happens :
If I change "alias /srv/www/blog/caller;" to a bad path, let say "alias /srvX/www/blog/caller;" I actually got the same behaviour in my browser, but
I can see in /var/log/nginx/error.log :
[error] 7229#0: *1 "/srvX/www/blog/caller/index.php" is not found (2: No such file or directory), client: 192.168.1.200, server: 192.168.1.221, request: "GET /blog/ HTTP/1.1", host: "192.168.1.221"
Conclusion : I don't know what's hapenning there : it seem clear that nginx get the file in my first try, but it sends the 404 error to the browser with no reason I could think of, while when specyfiyng a wrong path, it tells me right away. :/*
edit
Well, I found the solution. Basically it totally works from nginx, the problem was from php-fpm who lose his mind when using alias into nginx. What you need to do is doing a sublocation of aliased locations adding :
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
Now it works.
The fact that nginx was giving a 404 error without anything in the nginx's logs, was that php-fpm was the one failing to serve.
The problem is that you have no instructions on how to deal with the php script. To solve this issue the following:
Add the following code to your nginx.conf file within the server tags or if you have created that in your conf.d folder add it to that file.
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
That will solve that problem but also in the file:
/etc/php-fpm.d/www.conf
Ensure that listen.owner is set to listen.owner = nginx
Ensure that listen.group is set to listen.group = nginx
Restart both services and it should work.
If not ensure your document root and all files with that directory are owned by the user nginx and the group nginx.
If not you can do this by using the following:
chown -R nginx:nginx documentroot
And keep doing that but adding /* each time until you reach an error.
Hope everything works out for you!!
Amazon Linux lastest
PHP 5.4.19 (cli) (built: Sep 3 2013 23:19:23)
nginx version: nginx/1.2.9
installed PHP-FPM: PHP 5.4.19 (fpm-fcgi) (built: Sep 3 2013 23:22:01)
phpinfo() is working
pma.nginx.conf:
server {
listen 80;
server_name pma.my.server;
root /usr/share/phpmyadmin;
index index.php;
charset UTF-8;
access_log /var/log/myserver/pma.access.log;
error_log /var/log/myserver/pma.error.log;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /usr/share/phpmyadmin/;
fastcgi_intercept_errors on;
}
}
/var/log/myserver/pma.error.log:
[error] 21374#0: *13 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 1.0.255.202, server: pma.my.server, request: "GET /js/get_image.js.php?theme=pmahomme HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "pma.my.server", referrer: "http://pma.my.server/"
/var/log/php-fpm/error.log
NOTICE: fpm is running, pid 21598
NOTICE: ready to handle connections
WARNING: [pool www] child 21600 exited on signal 11 (SIGSEGV) after 12.862493 seconds from start
NOTICE: [pool www] child 21614 started
WARNING: [pool www] child 21602 exited on signal 11 (SIGSEGV) after 13.768522 seconds from start
NOTICE: [pool www] child 21617 started
/var/log/messages
kernel: [12499.658777] php-fpm[21603]: segfault at 0 ip 00000000005c5a39 sp 00007fffb44d6d60 error 4 in php-fpm[400000+31c000]
I don't have big experience with Nginx and FastCGI, so I need your help. Do you have any ideas? Thanks in advance
it appears that PHP is trying to write session data to disk in a directory that's not actually writable, namely /var/lib/php/session.
Thanks to Michael Hampton
The problem is php unable to write session to file but it not necessarily located in /var/lib/php/session
You can check and change it by using session_save_path
It appears there are a lot of things that can cause this, but if you are running a Magento website also check to see if any shopping cart rules were changed recently and see this relevant post. That was the solution for me.
The code in this file /js/get_image.js.php cause segment fault.
You can use core dump to view the backtrace.
Nginx Core dump