Apache, CGI, HTTP, HTTPS, Linux, modules, php Add comments
I need to make php-fpm listening on both tcp/UNIX socket, and this is how it done.
(this was not pretty workaround i guess, but it work ? )
first download php rpm source
Compile and install
$ rpmbuild –rebuild php-5.3.3-2.el5.src.rpm
$ sudo rpm -Uvh /path/to/RPMS/php-*
Configuring the default php-fpm for using tcp socket
Edit www.conf
$ sudo nano /etc/php-fpm.d/www.conf
Find line containing
listen = 127.0.0.1:9000
We can make it listening to port what ever we desire, ie 9001 etc
Start php-fpm first instance
$ sudo service php-fpm start
Configuring php-fpm for using unix socket
$ sudo cp /etc/php-fpm.conf /etc/php-fpm2.conf
$ sudo cp -rp /etc/php-fpm.d /etc/php-fpm2.d
Edit /etc/php-fpm2.conf
include=/etc/php-fpm2.d/*.conf
pid = /var/run/php-fpm/php-fpm2.pid
error_log = /var/log/php-fpm/error2.log
Edit /etc/php-fpm2.d/www.conf
listen = /tmp/php-fpm.sock
php_admin_value[error_log] = /var/log/php-fpm/www-error2.log
Copy The start up script in /etc/init.d/
$ sudo cp /etc/init.d/php-fpm /etc/php-fpm2
Make a view changes on php-fpm2 init script
01
#! /bin/sh
02
#
03
# chkconfig: – 84 16
04
# description: PHP FastCGI Process Manager
05
# processname: php-fpm
06
# config: /etc/php-fpm.conf
07
# pidfile: /var/run/php-fpm/php-fpm.pid
08
09
# Standard LSB functions
10
#. /lib/lsb/init-functions
11
12
# Source function library.
13
. /etc/init.d/functions
14
15
# Check that networking is up.
16
. /etc/sysconfig/network
17
18
if [ “$NETWORKING” = “no” ]
19
then
20
exit 0
21
fi
22
23
RETVAL=0
24
prog=”php-fpm2″
25
pidfile=${PIDFILE-/var/run/php-fpm/php-fpm2.pid}
26
lockfile=${LOCKFILE-/var/lock/subsys/php-fpm2}
27
28
start () {
29
echo -n $”Starting $prog: ”
30
daemon –pidfile ${pidfile} php-fpm2 –fpm-config /etc/php-fpm2.conf
31
RETVAL=$?
32
echo
33
[ $RETVAL -eq 0 ] && touch ${lockfile}
34
}
35
stop () {
36
echo -n $”Stopping $prog: ”
37
killproc -p ${pidfile} php-fpm2
38
RETVAL=$?
39
echo
40
if [ $RETVAL -eq 0 ] ; then
41
rm -f ${lockfile} ${pidfile}
42
fi
43
}
44
45
restart () {
46
stop
47
start
48
}
49
50
# See how we were called.
51
case “$1″ in
52
start)
53
start
54
;;
55
stop)
56
stop
57
;;
58
status)
59
status -p ${pidfile} php-fpm2
60
RETVAL=$?
61
;;
62
restart|reload|force-reload)
63
restart
64
;;
65
condrestart|try-restart)
66
[ -f ${lockfile} ] && restart || :
67
;;
68
*)
69
echo $”Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart}”
70
RETVAL=2
71
;;
72
esac
73
74
exit $RETVAL
Don’t forget to copy php-fpm binary in /usr/sbin/ driectory
1
$ sudo cp /usr/sbin/php-fpm /usr/sbin/php-fpm2
Start php-fpm2 unix socket instance
1
$ sudo service php-fpm2 start
Check it out if it’s successfuly listening on both tcp/unix socket
1
$ sudo netstat -pln | grep php-fpm
It’ll look like this
1
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1265/php-fpm
2
unix 2 [ ACC ] STREAM LISTENING 888664697 27700/php-fpm2 /tmp/php-fpm.sock
Finnaly, make all the work we’ve done get fixed
1
$ sudo chkconfig php-fpm on
2
$ sudo chkconfig php-fpm2 on
We can use it as backends for nginx upstream module
01
http {
02
……
03
……
04
upstream backend {
05
fair; # we can use upstream fair module here
06
server 127.0.0.1:9000;
07
server unix:/tmp/php-fpm.sock;
08
}
09
……
10
……
11
server {
12
location ~ .php$ {
13
fastcgi_pass backend;
14
fastcgi_index index.php;
15
…….
16
…….
17
include fastcgi_params;
18
}
19
……
20
……
21
}
22
}
that’s it, i hope it work on you too ?