Nginx + php-fpm on Amazon Linux = exited on signal 11 - nginx

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

Related

nginx on WSL2 takes minutes to load the page after few requests

I did read and try the following;
https://stackoverflow.com/a/46286973/8068675 listen = 127.0.0.1:9000;
https://stackoverflow.com/a/50615652/8068675 disable buffering
https://github.com/microsoft/WSL/issues/393#issuecomment-442498519 disable buffering + different config
But none of theses fixed the issue.
Issue
From Windows; when I browse my website located in WSL2 through http://myproject.test, https://myproject.test or 127.0.0.1 the first 2-3 requests are going fast (<100 ms). Then the next requests takes exactly 60000ms (1 minute) to be received when they are not blocked.
Configuration on Windows 10
Firewall disabled
127.0.0.1 myproject.test added to C:\Windows\System32\drivers\etc\hosts
mkcerts installed
WSL 2 installed with Ubuntu 20.04 on it
Configuration on WSL 2
Ubuntu 20.04
nginx 1.18
mysql 8.0
php-fpm 7.4
Project
Laravel
location /home/clement/projects/myproject/
certs (generated with mkcert) /home/clement/projects/certs/
owner: clement:www-data
permission : 777 (It's only for test and development purpose)
/etc/nginx/sites-available/myproject.test
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /home/clement/projects/certs/myproject.test.pem;
ssl_certificate_key /home/clement/projects/certs/myproject.test-key.pem;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
server_name myproject.test;
root /home/clement/projects/myproject/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_buffering off;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
include fastcgi_params;
}
}
I have the same issue using fastcgi_pass 127.0.0.1:9000; or fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
When I do php -S localhost:8080 or php artisan serve in the project, everything's working fine.
Edit with log
This is the log I'm getting on nginx, but even with this information I still cannot find any resource that fix the issue.
2020/08/07 23:06:30 [error] 1987#1987: *6 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: myproject.test, request: "GET /_debugbar/assets/javascript?v=1588748787 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "myproject.test", referrer: "http://myproject.test/"
Or using IP
2020/08/08 01:43:01 [error] 4080#4080: *4 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: myproject.test, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "myproject.test"
I finally found the issue. Despite I followed the instruction to install WSL 2, it was using WSL 1.
In powershell I ran
wsl -l -v and got the result
|---------------------|------------------|------------------|
| NAME | STATE | VERSION |
|---------------------|------------------|------------------|
| Ubuntu-20.04 | Stopped | 1 |
|---------------------|------------------|------------------|
After updating the kernel I could change the version to 2 with the command
wsl --set-version Ubuntu-20.04 2
and now everything works well

502 Bad Gateway with nginx and php7.0-fpm on docker

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

Getting Fatal Errors in Nginx to Be Shown in the Browser

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

nginx + php-fpm + pidora(fedora) on raspberry

I would like to make the configuration what mentioned in the subject.
If I start the nginx I see this error message in /var/log/nginx/error.log
*1 connect() to unix:127.0.0.1:9000 failed (2: No such file or directory) while connecting to upstream
I tried to set with socket. I get the following error
unix:/var/run/php5-fpm.sock failed (2: No such file or directory)
Seems the nginx need a file or not the path is bad. Exactly I not understand how can I solve it,
Here is my nginx settings
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params; }
when I tried with socket I used this ( fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock;)
I change in /etc/php-fpm/www.conf only the "listen" attribute depends on fastcgi_pass.
Anyone has an idea how can I solve it?
Update:
I changed fastcgi_pass unix:127.0.0.1:9000 to fastcgi_pass 127.0.0.1:9000
In this case I got the following error
*1 connect() failed (111: Connection refused) while connecting to upstream,
And the following messages when I started the php-fpm
Oct 17 09:30:31 raspi php-fpm[6605]: [17-Oct-2013 09:30:31] ALERT: [pool www] user has not been defined
Oct 17 09:30:31 raspi php-fpm[6605]: [17-Oct-2013 09:30:31] ERROR: failed to post process the configuration
Oct 17 09:30:31 raspi php-fpm[6605]: [17-Oct-2013 09:30:31] ERROR: FPM initialization failed
Oct 17 09:30:31 raspi systemd[1]: php-fpm.service: main process exited, code=exited, status=78/n/a
Oct 17 09:30:31 raspi systemd[1]: Unit php-fpm.service entered failed state
Solved
I had to set the following users in the php-fpm
user
group
listen.owner
listen.group

PHP-FPM - upstream prematurely closed connection while reading response header

Already saw this same question - upstream prematurely closed connection while reading response header from upstream, client
But as Jhilke Dai said it not solved at all and i agree.
Got same exact error on nginx+phpFPM installation. Current software versions: nginx 1.2.8 php 5.4.13 (cli) on FreeBSd9.1. Actually bit isolated this error and sure it happened when trying to import large files, larger than 3 mbs to mysql via phpMyadmin. Also counted that backend closing connection when 30 secs limit reached.
Nginx error log throwing this
[error] 49927#0: *196 upstream prematurely closed connection while reading response header from upstream, client: 7X.XX.X.6X, server: domain.com, request: "POST /php3/import.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock2:", host: "domain.com", referrer: "http://domain.com/phpmyadmin/db_import.php?db=testdb&server=1&token=9ee45779dd53c45b7300545dd3113fed"
My php.ini limits raised accordingly
upload_max_filesize = 200M
default_socket_timeout = 60
max_execution_time = 600
max_input_time = 600
my.cnf related limit
max_allowed_packet = 512M
Fastcgi limits
location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/tmp/php5-fpm.sock2;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort on;
fastcgi_connect_timeout 60s;
fastcgi_send_timeout 200s;
fastcgi_read_timeout 200s;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
Tried to change fastcgi timeouts as well buffer sizes, that's not helped.
php error log doesn't show problem, enabled all notices, warning - nothing useful.
Also tried disable APC - no effect.
I had this same issue, got 502 Bad Gateway frequently and randomly at my development machine (OSX + nginx + php-fpm), and solved it by changing some parameters at /usr/local/etc/php/5.6/php-fpm.conf:
I had this settings:
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.max_spare_servers = 5
... and changed them to:
pm = dynamic
pm.max_children = 10
pm.start_servers = 10
pm.max_spare_servers = 10
... and then restarted the php-fpm service.
This settings are based on what I found here: [https://bugs.php.net/bug.php?id=63395]
How long does your script take to compute? Try to set, both in PHP and Nginx HUGE timeouts and monitor your system during the request. Then tune your values to optimise performance.
Also, lower the log level in PHP-FPM, maybe there is some type of warning, info or debug trace that can give you some info.
Finally, be careful with the number of children and processes available in PHP-FPM. Maybe Nginx is starving, waiting for a PHP-FPM child to be available.

Resources