1.安裝php5
代碼如下 |
複製代碼 |
apt-get install php-pear php5-cli php5-common php5-cgi php5-mysql php5-gd php5-dev |
2.安裝mysql5
代碼如下 |
複製代碼 |
apt-get install mysql-server mysql-client libipc-sharedcache-perl
|
3.安裝nginx
代碼如下 |
複製代碼 |
apt-get install nginx
|
配置nginx如下
代碼如下 |
複製代碼 |
sudo vi /etc/nginx/sites-available/default |
修改點如下
代碼如下 |
複製代碼 |
#這行增加index.php為預設檔案 index index.php index.html index.htm; |
啟用fastcgi處理php指令碼
代碼如下 |
複製代碼 |
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; } |
4.建立fastcgi的控制指令碼
代碼如下 |
複製代碼 |
sudo vi /etc/init.d/php-cgi
|
內容如下
代碼如下 |
複製代碼 |
#!/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 |
給/etc/init.d/php-cgi加上執行許可權
代碼如下 |
複製代碼 |
sudo chmod +x /etc/init.d/php-cgi |
啟動php-cgi進程
代碼如下 |
複製代碼 |
sudo /etc/init.d/php-cgi start |
要讓php-cgi隨系統開機啟動,可以通過如下命令
代碼如下 |
複製代碼 |
sudo update-rc.d php-cgi defaults 25 |