上周六测试了lighttpd,很简单,安装和支持PHP一下子就通过了,今天又了解了下nginx服务,为什么去了解它,因为现在国内很多大型的网站都使用nginx做为web server,比如yo2,新浪博客等等,还有很多都是使用nginx,其性能在apache之上,所以得学学了。
还是以FreeBSD7.0为例
1,首先安装MySQL-Server-5.0,以ports方式安装
#cd /usr/ports/databases/mysql50-server && make install clean
安装漫长,上个洗手间没问题。
2,php5安装
#cd /usr/lang/php5/ && make install clean 选择对cgi mysql等的支持
3,cd /usr/devel/pcre && make install clean
4,因为nginx跑PHP需要fastcgi支持,所以需要下载lighttpd包编译,不需要安装,编译后产生spawn-cgi
#cd /usr/ports/www/lighttpd && make
#cp /usr/ports/www/lighttpd/work/lighttpd-version/src/spawn-cgi /usr/bin #复制spawn-cgi到/usr/bin目录下
#make clean #删除下载回来的lighttpd文件
5,修改配置文件/usr/local/etc/nginx/nginx.conf
去除以下配置文件中的#号,再设置第二行的user www www以www用户和组运行,保存
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
include fastcgi_params;
}
6,修改PHP.ini文件中的cgi.fix_pathinfo=1 这样php-cgi方能正常使用SCRIPT_FILENAME这个变量。
7,启动fcgi
#/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi
参数说明:
-f <fcgiapp> 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
-a <addr> 绑定到地址addr
-p <port> 绑定到端口port
-s <path> 绑定到unix socket的路径path
-C <childs> 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
-P <path> 指定产生的进程的PID文件路径
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等
8,测试与启动nginx
测试:nginx -t -c /usr/local/etc/nginx/nginx.conf 测试配置是否正确
如果屏幕显示以下两行信息,说明配置文件正确:
www# nginx -t -c /usr/local/etc/nginx/nginx.conf
2008/07/21 16:58:13 [info] 33772#0: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
2008/07/21 16:58:13 [info] 33772#0: the configuration file /usr/local/etc/nginx/nginx.conf was tested successfully
启动:
/usr/local/etc/rc.d/nginx start
9,加入开机自动启动/etc/rc.conf
nginx_enable=”YES”
10,phpinfo测试
写入以下内容至/usr/local/etc/www/nginx/phpinfo.php
<? phpinfo();?>
如果正常输出PHP配置信息,则配置成功!
另外需要补充一点:
如需要安装WordPress和CMS之类程序,还需要安装PHP扩展,php5-extensions
#cd /usr/ports/lang/php5-extensions/ && make install clean
选中需要安装与支持的模块。
Powered by MightyAdsense
2 条评论了已经
发表评论
字体为 粗体 是必填项目,邮箱地址 永远不会 公布。
允许部分 HTML 代码:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs(网站链接)必须完整有效 (比如: http://www.23day.com),所有标签都必须完整的关闭。
超出部分系统将会自动分段及换行。
请保证评论内容是与日志或 Blog 内容相关的,灌水、攻击性或不恰当的评论 可能 会被编辑或删除。
看来要尝试使用nginx了
这个东东是很不错,比apache要小巧多了