Ubuntu :: PHP FastCGI + NGINX
:: How to setup PHP FastCGI for NGINX in Ubuntu
+ Installing NGINX and php-cgi
apt-get update apt-get install nginx php5-cli php5-cgi spawn-fcgi
+ Make php-fcgi script in init.d
vi /etc/init.d/php-fcgi
add these line:
#!/bin/bash BIND=127.0.0.1:9000 USER=www-data PHP_FCGI_CHILDREN=15 PHP_FCGI_MAX_REQUESTS=1000 PHP_CGI=/usr/bin/php-cgi PHP_CGI_NAME=`basename $PHP_CGI` PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND" RETVAL=0 start() { echo -n "Starting PHP FastCGI: " start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS RETVAL=$? echo "$PHP_CGI_NAME." } stop() { echo -n "Stopping PHP FastCGI: " killall -q -w -u $USER $PHP_CGI RETVAL=$? echo "$PHP_CGI_NAME." } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Usage: php-fastcgi {start|stop|restart}" exit 1 ;; esac exit $RETVAL
+ change permission anda run the script when booting
chmod +x /etc/init.d/php-fcgi update-rc.d php-fcgi defaults
+ setup PHP FastCGI in NGINX
vi /etc/nginx/sites-enabled/blackonsole.org
add line in server {} like these:
location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/blackonsole.org$fastcgi_script_name; keepalive_timeout 0; }
so the configuration like:
server { listen 80; error_log /var/log/nginx/blackonsole.org-error.log access_log /var/log/nginx/blackonsole.org-access.log root /var/www/blackonsole.org; index index.php index.html index.htm; # Make site accessible from //localhost/ server_name blackonsole.org; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules if (!-e $request_filename) { rewrite ^(.*)$ /index.php?q=$1 last; break; } } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { # fastcgi_split_path_info ^(.+.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/blackonsole.org$fastcgi_script_name; keepalive_timeout 0; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; } }
+ restarting NGINX and php-fcgi
/etc/init.d/nginx restart /etc/init.d/php-fcgi restart
+ checking the daemon
netstat -tlupn
make sure you see nginx and php-fcgi service
thanks guys. it’s work. apparently nginx in ubuntu require spawn-fcgi for access php script. big thanks