0

Nginx gives bad 502 gateway, the log says

*205 connect() failed (111: Connection refused) while connecting to upstream

And sure enough, the 9000 socket isn't open.

The problem is: I don't know how to open this port. Other questions address this issue for php-fpm, suggesting to use a unix socket. However this doesn't seem applicable here because there is no php-fpm.conf for php-5.3.3.

I am using centos 5.3.

3 Answers 3

2

You can install the remi repo which contains php 5.3.x and php-fpm, and allows you to maintain everything in your package manager. I have used this repo for CentOS versions 5.7 all the way to 6.3. You are more than available to compile php-fpm via the instructions provided here and follow the instructions for the ini configuration here, but I find them highly over complicated, and difficult to maintain as they are outside of package management.

Enterprise Linux 5 (with EPEL)

wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm 
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm 
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

Enterprise Linux 6 (with EPEL)

wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

Once you have this repo installed, you will be able to search the repo so that you can find whatever PHP you need.

[root@puppetmaster ~]# yum list php.x86_64 --enablerepo=remi
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: centos.mirrors.chicagovps.net
 * epel: mirror.steadfast.net
 * extras: mirror.steadfast.net
 * remi: remi-mirror.dedipower.com
 * updates: centos.mirrors.chicagovps.net
Available Packages
php.x86_64                                               5.3.18-1.el6.remi                                               remi

[root@puppetmaster ~]# yum list php-fpm --enablerepo=remi
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: yum.singlehop.com
 * epel: mirror.steadfast.net
 * extras: mirror.steadfast.net
 * remi: remirpm.mirror.gymkl.ch
 * updates: mirror.steadfast.net
Available Packages
php-fpm.x86_64                                             5.3.18-1.el6.remi                                             remi

You are more than able to search for anything that you may need to get out of the repo, whether it be mbstring, mcrypt, mysql, mysqlnd.

Once you have everything installed to your wishes, you can simply start php-fpm like you would any other service.

[root@puppetmaster ~]# service php-fpm start
Starting php-fpm:                                          [  OK  ]

You will need to configure nginx to know what the upstream is, this can be done via nginx.conf inside the http {} level of the config, by default php-fpm will start using port 9000

[root@puppetmaster ~]# netstat -na | grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN

You can change how your pool is created by editing your [something] pool to reflect something like this.

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

The below allows you to create an alias that you can use to simple the readability of your configs.

upstream  base_backend {
    #server unix:/var/run/php-fpm.sock;
    server 127.0.0.1:9000;
}

You can direct your PHP scripts inside your server {} level of the config so that php-fpm will actual execute them.

location ~ \.php$ { ## Execute PHP scripts
    expires        off; ## Do not cache dynamic content
    fastcgi_pass   base_backend;
    fastcgi_param  HTTPS $fastcgi_https;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params; ## See /etc/nginx/fastcgi_params
}
0

You can install FPM on CentOS by several ways:

  1. You can install additional repository and install php-fpm package from it (for example, it is described here)
  2. Or you can install php-fpm from source (all steps are provided here, but this blog is on Russian, so you have to use Google Translate).
1
  • 1. seems to be for centos 5.8
    – Adripants
    Oct 30, 2012 at 10:27
0

Port 9000 need to connect to a php-fpm daemon. Sounds like php-fpm is not started.

Check your ps listing to see if php-fpm is there. Also, you mention a "socket". PHP fpm supports unix sockets, but the setup is different from TCP.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .