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

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

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

my nginx doesn't display php file at centos7

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"

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

Nginx 504 Time-out with php-fpm

I got 504 Gateway Time-out for one of my sites. Please, help to find out why?
Here's my nginx configuration:
server {
listen 80;
server_name domain.com;
root /home/user/domain.com;
error_log /home/user/domain.com/error.log;
location / {
try_files $uri /index.php?q=$uri&$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Nginx error log:
$ sudo tail -n 1 domain.com/error.log
2014/08/21 17:09:35 [error] 16790#0: *30 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 5.18.54.52, server: domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock", host: "domain.com"
And nothing in php-fpm log:
sudo tail -n 1 /var/log/php5-fpm.log
[21-Aug-2014 17:08:31] NOTICE: ready to handle connections
And here my www.conf:
$ sudo nano /etc/php5/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 1
pm.max_spare_servers = 10
Please help me to solve this! Thanks!
As of PHP 5.5.12 FPM Socket permissions were changed to resolve a security related bug, you can read more about that here -> https://bugs.php.net/bug.php?id=67060
Your listen.mode = 0660 should now be set to listen.mode = 0666 inside of your FPM Pool Configuration. Also make certain that your listen.owner and listen.group is the same user name/group that is running Nginx. Here is what I have in my setup:
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
I am assuming that your Nginx Configuration has user www-data; then simply change the nginx reference I have above to www-data of course.
As for Nginx here is a working example I am currently using:
# PHP-FPM Support
location ~ \.php$ {
fastcgi_pass unix:/var/run/nginx.sock;
include fastcgi.conf;
}
I think your Nginx Configuration is just fine, but in case you wanted to try something a little different I'm posting my config as a test for you.
Don't forget to restart PHP-FPM after making any configuration changes too.
Give this a try, I'm certain it should resolve your problem.

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

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

Resources