Install Required Packages
Update & upgradeapt-get install mysql-server nginx php5-cli php5-cgi spawn-fcgi nginx php5-cli php5 -cgi spawn-fcgi php5-gd php5-mysql
2 Create directories for Your Site
mkdir -p/srv/www/yourdomain/public_htmlmkdir/srv/www/yourdomain/logschown-r www-data:www-data/srv/www/ YourDomain
3 Configuration
I'll use UNIX Sockets to run PHP.
Vi/etc/nginx/sites-enabled/yourdomain
Server{server_nameWww.yourdomain.com yourdomain.com;Access_log/srv/www/yourdomain/logs/access.log;Error_log/srv/www/yourdomain/logs/error.log;Root/srv/www/yourdomain/public_html; Location/ {IndexIndex.html index.htm; } Location ~ \.php${include/etc/nginx/fastcgi_params;Fastcgi_pass Unix:/var/run/php-fastcgi/php-fastcgi.socket; Fastcgi_indexindex.php;Fastcgi_paramScript_filename/srv/www/yourdomain/public_html$fastcgi _script_name; }}# rewrite Server{server_nameyourdomain.com;rewrite ^/(.*) http://www. $host/$1 Permanent;}
4 Create A file named/usr/bin/php-fastcgi with the following contents:
vi/usr/bin/php-fastcgi
Note : fastcgi_user=www-data, USER www-data in nginx configuration file ;
#!/bin/bash $SOCKET $PIDFILE $CHILDREN $FASTCGI _user $FASTCGI _group $PHP 5
5 Make it executable by issuing the following command:
chmod +x/usr/bin/php-fastcgi
6 Create A file named/etc/init.d/php-fastcgi with the following contents:
vi/etc/init.d/php-fastcgi
#!/bin/bashPhp_script=/usr/bin/php-fastcgifastcgi_user=www-datafastcgi_group=www-datapid_dir=/var/run/php-fastcgipid_file =/var/run/php-fastcgi/php-fastcgi.pidret_val=0case"$" inchStartif [[!-D $PID _dir ]] ThenMkdir$PID _dirChown$FASTCGI _user:$FASTCGI _group $PID _dirchmod 0770$PID _dir fi if [[-R $PID _file ]] Then Echo "php-fastcgi already running with PID ' cat $PID _file'"Ret_val=1Else $PHP _scriptRet_val=$?fi;; Stopif [[-R $PID _file ]] ThenKill ' Cat$PID _file' RM$PID _fileRet_val=$?Else Echo "Could not find PID file $PID _file"Ret_val=1fi;; Restartif [[-R $PID _file ]] ThenKill ' Cat$PID _file' RM$PID _fileRet_val=$?Else Echo "Could not find PID file $PID _file" fi $PHP _scriptRet_val=$? ;; Statusif [[-R $PID _file ]] Then Echo "php-fastcgi running with PID ' cat $PID _file'"Ret_val=$?Else Echo "Could not find PID file $PID _file, php-fastcgi does not appear to be running" fi;; *)Echo "usage:php-fastcgi {start|stop|restart|status}"ret_val=1;; EsacExit $RET _val
7 Start php-fastcgi and Nginx by issuing the following commands:
Update Start Start
8 Test PHP with FastCGI
<?php ?>
Deploy Nginx + Mysql + spawn-fcgi on Debian/ubuntu