ubuntu 12.04下的nginx+php安装和配置

来源:互联网 发布:中信银行淘宝卡 编辑:程序博客网 时间:2024/05/08 08:47

1.apt-get install nginx
安装nginx
2.apt-get install php5-cli php5-cgi mysql-server php5-mysql
安装php和mysql
3.apt-get install spawn-fcgi
安装spawn-fcgi,用来启动php-cgi
4.修改/etc/nginx/sites-available/default
在server {
这一项里,加上
listen 8080;
5./etc/init.d/nginx restart
重启nginx
网页代码在/usr/share/nginx/www/

http://localhost:8080/

默认打开的是index.html
6.写一个php脚本

<?php
echo phpinfo();
?>
被当作普通文件下载
这是由于/etc/nginx/sites-available/default
中匹配了 location /
导致被当作普通的文件下载。
所以需要加一个新的规则:

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
这样index.php就会被当作php文件被解析执行。

0 0