2013年4月6日星期六

ubuntu linux 下配置启用php

linux 系统,nginx服务器,php语言环境
nginx已安装配置好,启用并且测试成功.
php已安装好,并且测试成功.

在vi中写好hello.php,在浏览器中打开文件,却是下载文件提示.
很明显,我的nginx并没有配置php的服务模块,默认情况下,web服务器只能解析html静态文件,所以需要手动配置.

首先,nginx -t,查看配置文件的路径,在/etc/nginx/nginx.conf
打开nginx.conf文件,并没有找到php启用模块
查找include,发现nginx.conf文件有两个include文件,分别是
/etc/nginx/sites-enabled/default  和
/etc/nginx/conf.d/*.conf

分别查找,发现 /etc/nginx/sites-enabled/default 文件中有php相关模块
location ~\.php${...}模块,去掉前面的注释符号#(除了说明部分),保存配置文件.


重启nginx服务 :
nginx -s reload
再次测试 nginx -t 提示test is successful.
刷新浏览器hello.php页面,显示hello world,表明配置完成.


如果一次测试不能成功,多试几次location ~\.php${...}模块,总会成功的.

没有评论:

发表评论