Make PHP-FPM Listen at 'IPAddress:Port' Instead of '/var/run/php5-fpm.sock;'
Solution 1
I used $ sudo php5-fpm -t
command to test if PHP-FPM's settings are fine (if not, it'll show me some error/info).
So, here's what the output looked like:
[13-Feb-2013 18:35:00] ERROR: [/etc/php5/fpm/pool.d/www.conf:33] value is NULL for a ZEND_INI_PARSER_ENTRY
[13-Feb-2013 18:35:00] ERROR: Unable to include /etc/php5/fpm/pool.d/www.conf from /etc/php5/fpm/php-fpm.conf at line 33
[13-Feb-2013 18:35:00] ERROR: failed to load configuration file '/etc/php5/fpm/php-fpm.conf'
[13-Feb-2013 18:35:00] ERROR: FPM initialization failed
The error says, something's wrong in Line 33 of of /etc/php5/fpm/pool.d/www.conf
, which happens to be this: listen 127.0.0.1:9000
(not so much of a coincidence, is it?).
After seeing it, I immediately compared it with other lines, and then it struck me, an =
(equal-to sign) is missing!
So, this is what it's supposed to be: listen = 127.0.0.1:9000
and that fixed everything!
Solution 2
Sounds like (based on the 502 and the error message) that php-fpm service is failing to start.
Could something else be using port 9000? To check run:
sudo lsof -P | grep TCP | grep LISTEN
and look for something like TCP localhost:9000 (LISTEN)
. If there is, you could just use a different port, say 9001.
Good place to check would be the php-fpm error log. It may not be enabled by default. If you look at your php-fpm conf file (/etc/php5/fpm/php-fpm.conf on my system) you'll find the 'error_log' setting. This is the path to your error log. If this is commented out, un-comment it, restart the php-fpm service again and check what the contents of the log file say.
Solution 3
You can use IP/port or Unix socket on your choices.
This depends on your php-fpm config, the file is www.conf
, in my system (Ubuntu 16.04), this file located at /etc/php/7.0/fpm/pool.d
.
Within this file, you can find a directive named listen
, if you set this directive to /run/php/php7.0-fpm.sock
, for example, then in your nginx site config fastcgi_pass
should be unix:/run/php/php7.0-fpm.sock
;
But if you set listen to 127.0.0.1:9000
, then fastcfg_pass
should be 127.0.0.1:9000
.
Related videos on Youtube
its_me
Updated on September 18, 2022Comments
-
its_me over 1 year
As I was load testing my site today (using blitz.io); despite lots of RAM (more than 50%) and CPU power (over 70%) available, results showed that my site started timing out at a certain number of concurrent users per second.
Nginx error log for my site (/var/log/nginx/example.com.error.log) showed something like this:
2013/02/12 19:03:57 [error] 13749#0: *3175 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 54.123.456.46, server: example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "example.com"
Googling the error led me to this answer which states using TCP\IP connection instead of unix socket as the solution to the problem; as unix socket's "problems on high-load cases is well-known".
So, as suggested by the answer:
I replaced
listen = /var/run/php5-fpm.sock
withlisten 127.0.0.1:9000
in /etc/php5/fpm/pool.d/www.confAs there's no
/etc/nginx/php_location
on my distrio (Debian Wheezy), I did nothing about it.Since I use
fastcgi_pass unix:/var/run/php5-fpm.sock;
in the Nginx configuration file for my site, i.e., /etc/nginx/sites-available/example.com, I replaced it withfastcgi_pass 127.0.0.1:9000;
Now the problem is, I get a
502 Bad Gateway
error when I visit my website. Yes, I didreload
Nginx and PHP-FPM. What am I doing wrong? (A total newbie here, doing my best to learn by doing.)In case this is relevant, when I do
sudo service php5-fpm restart
, I get this error:[FAIL] Restarting PHP5 FastCGI Process Manager: php5-fpm failed!
And this is happening only since I made the aforementioned changes. How can I fix this?
Please let me know if I should get more information.
UPDATE
The file
/etc/nginx/sites-available/default
says this:# # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock;
So, does that mean, if my server is running PHP-FPM, it SHOULD, without a choice, use
/var/run/php5-fpm.sock
?-
mgorven over 11 yearsPlease paste your entire
www.conf
.
-
its_me over 11 years(1) No, port 9000 doesn't seem to be used by any other service. Here's the output of
$ sudo lsof -P | grep TCP | grep LISTEN
(2) here are the contents of PHP-FPM log file at/var/log/php5-fpm.log
-- paste.kde.org/670802, I still dont understand what to do...?! -
chrskly over 11 yearsLooks like it's still trying to use the file socket
NOTICE: using inherited socket fd=6, "/var/run/php5-fpm.sock"
. Is there a listen setting in /etc/php5/fpm/php-fpm.conf? -
its_me over 11 yearsNo. But it has this:
include=/etc/php5/fpm/pool.d/*.conf
which probably means it includes /etc/php5/fpm/pool.d/www.conf, in which I did make changes as mentioned in my question. -
its_me over 11 yearsI got more information from
sudo php5-fpm -t
: paste.kde.org/670826 -- as shown in the error, line 33 of /etc/php5/fpm/pool.d/www.conf is this:listen 127.0.0.1:9000
-
its_me over 11 yearsThe line 33 of www.conf is
listen 127.0.0.1:9000
which I am using instead oflisten = /var/run/php5-fpm.sock
as the latter is causing time outs under load (as mentioned in my question).