CentOS / Red Hat PHP FastCGI script For Ngnix / Lighttpd / Apache Webserver

Posted on in Categories Web Server last updated April 22, 2009

A shell script to start / stop / restart php-cgi as an app server. By default it will bind to 127.0.0.1 IP and 9000 port using spawn-fcgi. This script is tested on CentOS / RHEL / Fedora Linux only. FreeBSD specific version available here.

How do I use this script?

Install spawn-fcgi package using yum command.

Download this script and place in /etc/init.d/ directory as /etc/init.d/php_cgi
# wget http://bash.cyberciti.biz/dl/419.sh.zip -O /etc/init.d/php_cgi
# chmod +x /etc/init.d/php_cgi

php_cgi init.d sysv style script

5 comment

  1. if you run the web server in the same machine, better you use unix sockets .. modify this couple lines

    ~24
    #server_ip=127.0.0.1
    #server_port=9000
    server_socket=/var/lib/php/php-cgi.sock

    ~40
    #daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}
    daemon $spawnfcgi -s ${server_socket} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}

  2. I have used this script with CentOS 5.5. I have nginx, php5 installed following your tutorial. I installed spawn-fcgi with yum from epel. I have in chkconfig a service called spawn-fcgi and a service called php_cgi.
    if i run service spawn-fcgi it doesn’t start whereas service php_cgi start works great!
    When the server reboot it does not start php_cgi auomatically..why?
    Thanks.

Leave a Comment