1,sudo apt-get install php5 //安装PHP5
2,必须安装的:apt-get -y install php5-cgi sudo apt-get install spawn-fcgi
3,/usr/bin/php-cgi -b 127.0.0.1:9000 -c /etc/php5/cgi/php.ini 启动php,看是否可用。
4,创建php-cgi快速启动文件 加入自动启动。
脚本:
#!/bin/sh
dir=`dirname $0`
PID_FILE="/etc/php5/cgi/php.ini"
PHP_FCGI="/usr/bin/php-cgi -f /etc/php5/cgi/php.ini"
case "$1" in
'start')
spawn-fcgi -C 3 -p 9000 -f "$PHP_FCGI" -P $PID_FILE
;;
'stop')
kill `cat $PID_FILE`
;;
'restart')
kill `cat $PID_FILE`
spawn-fcgi -C 3 -p 9000 -f "$PHP_FCGI" -P $PID_FILE
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
php-cgi管理脚本:
ln -s /etc/init.d/php-cgi /etc/rc1.d/K80php
ln -s /etc/init.d/php-cgi /etc/rc2.d/S20php
ln -s /etc/init.d/php-cgi /etc/rc3.d/S20php
ln -s /etc/init.d/php-cgi /etc/rc4.d/S20php
ln -s /etc/init.d/php-cgi /etc/rc5.d/S20php
之后重启nginx /etc/init.d/php-cgi restart
5,创建phpinfo.php文件,在nginx server映射的目录下。
<?php
phpinfo();
?>
6,打开了mysql扩展,没有的话修改php.ini
;extension=php_mysql.dll
extension=mysql.so
extension=php_mysql.dll
7,配置nginx服务。
nginx 服务器配置
server{
listen 80;
server_name 域名;
charset utf-8;
root /var/wordpress;
index index.php index.html index.shtml;
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ {
root /var/wordpress;
expires 24h;
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
}
location ~ .*\.(php|php5)?$ {
root /var/wordpress;
fastcgi_param SCRIPT_FILENAME /var/wordpress/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
#error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 500 501 502 503 504 505 = /404.html;
}