nginx+php-cgi+spawn-fcgi

Apache+php — old pack, good, stable, but very voracious in comparison with nginx

install nginx php5 php-cgi spawn-fcgi.

#variant 1

start php-cgi with spawn-fcgi:

spawn-fcgi -f /usr/bin/php-cgi -a 127.0.0.1 -p 9000 -C 2 -P /var/log/nginx/php.pid -u www-data -g www-data

#variant2

using unix sockets:

exec /usr/bin/spawn-fcgi -s /tmp/php-cgi.sock /usr/bin/php-cgi -C 2 -P /var/log/nginx/php.pid -u www-data -g www-data

Write a script to run several processes:

1
2
3
4
5
6
7
8
#!/bin/bash
exec 2>&1
PHP_FCGI_CHILDREN=3 \
PHP_FCGI_MAX_REQUESTS=1000 \
#Variant 1
#exec /usr/bin/spawn-fcgi -f /usr/bin/php-cgi -a 127.0.0.1 -p 9000 -C 2 -P /var/log/nginx/php.pid -u www-data -g www-data
#Variant 2
exec /usr/bin/spawn-fcgi -s /tmp/php-cgi.sock /usr/bin/php-cgi -C 2 -P /var/log/nginx/php.pid -u www-data -g www-data

spawn-fcgi — one of the components of the project Lighttpd. It is intended for that to run a php, as a FastCGI server, well, the server can handle and then almost any http server.

nano /etc/nginx/sites-available/default:

location / {

root /var/www/nginx-default;

index index.php index.html index.htm;

}

location ~ \.php$ {
fastcgi_intercept_errors on;
#Вариант 1
#fastcgi_pass 127.0.0.1:9000;
#Вариант 2
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include fastcgi_params;
}

/etc/init.d/nginx start