nginx (1)
php (1)

How do get PHP CGIs working with nginx on CentOS?

I want to use PHP via the FastCGI interface with nginx on CentOS. How do I do that?

yum install php-cli should get php-cgi installed. It landed in /usr/bin for me.
You need something to launch a php-cgi process 'cause nginx won't start processes for you. I put this in a shell script file:

#!/bin/bash
export BIND=127.0.0.1:9000
export USER=nginx
export PHP_FCGI_CHILDREN=15
export PHP_FCGI_MAX_REQUESTS=1000
export PHP_CGI=/usr/bin/php-cgi
nohup $PHP_CGI -b $BIND &

Don't forget to chmod it executable. You don't actually need to export some of those. I was playing around and didn't edit any of this for perfection. that's your job.

Then you need to mod your nginx config. I added something like this:

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
        include fastcgi_params;
    }

run your php-cgi script
Re(start|load) your nginx.

Comments

Add a Comment



NOTE: Comments are moderated and will not show until approved.