|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
| |
| 在Zeus Web Server中安装PHP语言支持 |
|
前言 YBFLinux联盟 Zeus是一个运行于Unix下的非常优秀的Web Server,而PHP则是Unix下一个非常优秀的后台脚本语言。 这两个产品都是为非常喜欢的产品。为什么要写这样的一个Howto呢?是因为有大量的网站脚本是使用PHP开发的, 而这些程序运行在Zeus下也是一个非常好的选择。写这份文档的目的在于能让大家的PHP系统良好的运行于Zeus服务器上。 YBFLinux联盟 很早的时候我写过一份整合Zeus和PHP的文章,它主要是讲如何将PHP以FastCGI的本地调用方式来运行于Zeus中的, 本份Howto主要是来讲如何让PHP运行于Remote Responders方式下。因为这样会比以local方式有更高的可扩展性和运行效率。 YBFLinux联盟 YBFLinux联盟 准备工作 YBFLinux联盟 首先你应该Zeus安装完成,也不会过多的讲如何安装和配置Zeus服务器本身,因为它的安装和配置实在是太简单了。 YBFLinux联盟 如果有可能,最好将ports使用cvsup来升级一下。 YBFLinux联盟 对于PHP依赖的相关软件如果能提前装,则从ports中安装好。如MySQL、GD等。 安装fastcgi YBFLinux联盟 注意,如果你安装的PHP的版本会低于4.3.0哪么你才需要这步。新的PHP版本已经内置了fastcgi的库。安装fastcgi的方法非常的简单: YBFLinux联盟 YBFLinux联盟 root@~$cd /usr/ports/www/fcgi/ YBFLinux联盟 root@/usr/ports/www/fcgi$make;make install;make clean YBFLinux联盟 编译完成后我们可以在/usr/local/lib目录中看到有libfcgi.a文件,同时在/usr/local/include目录中会有fastcgi的所有头文件。 YBFLinux联盟 YBFLinux联盟 YBFLinux联盟 YBFLinux联盟 编译PHP YBFLinux联盟 编译PHP可以使用通常的PHP编译选项,下面是我使用的一个配置: YBFLinux联盟 YBFLinux联盟 ./configure --prefix=/usr/local/php --enable-fastcgi --with-mysql=/usr/local YBFLinux联盟 需要注意的是在PHP 4.3.0以上版本是使用的 --enable-fastcgi 选项,而PHP 4.3.0以前的版本应使用--with-fastcgi参数。 YBFLinux联盟 接着就是安装PHP到系统中: YBFLinux联盟 make YBFLinux联盟 make install YBFLinux联盟 编译完成后,我们来测试一下安装的php是能正确运行: YBFLinux联盟 YBFLinux联盟 root@~$cd /usr/local/php/bin/ YBFLinux联盟 root@/usr/local/php/bin$./php YBFLinux联盟 这时将进入php代码输入状态,输入 YBFLinux联盟 YBFLinux联盟 <? phpinfo(); ?> YBFLinux联盟 按ctrl-d运行后会见到php返回的信息则为正确。 YBFLinux联盟 YBFLinux联盟 配置FastCGI/PHP YBFLinux联盟 配置FastCGI YBFLinux联盟 进入Zeus管理控制台,打开需要配置的VHost配置。进入 API Support 中的 FastCGI 设置。在其中设置: YBFLinux联盟 Enabling Support for FastCGI Programs : Enable YBFLinux联盟 在Configuring FastCGI Remote Responders中设置: YBFLinux联盟 Directory name : /usr/local/php/bin/php YBFLinux联盟 Location: Machine name: localhost YBFLinux联盟 Additional methods supported?:None YBFLinux联盟 如果你的PHP应用不在本机,即使PHP没有安装在本机上,哪么也要设置 Docroot path 参数,它可以不存在于相应的目录下。 YBFLinux联盟 都设置完成后,点击 Apply 按钮。 配置PHP解析指向 YBFLinux联盟 进入 URL Handling 中的 Handlers 设置。在 Adding a Handler 中设置以下参数: YBFLinux联盟 YBFLinux联盟 File Extension : php YBFLinux联盟 Specify the path and filename of the handler, relative to the document root : /usr/local/php/bin/php YBFLinux联盟 HTTP 404 errors are handled by : The handler YBFLinux联盟 注意,这里的 Specify the path and filename of the handler, relative to the document root 应和你上一步设置的 Directory name 值相同。 YBFLinux联盟 都设置完成后,点击 Apply 按钮。 YBFLinux联盟 所有的设置完成后使用vhost的commit功能将更 改提交并应用。这样Zeus就设置好了Fastcgi和PHP的相关参数。 YBFLinux联盟 YBFLinux联盟 配置FastCGI/PHP启动 YBFLinux联盟 在Zeus的rc.d目录中新建一个S05php的文件,内容为: YBFLinux联盟 YBFLinux联盟 #!/bin/sh YBFLinux联盟 YBFLinux联盟 # Script to start and stop the persistent PHP runner for FastCGI. YBFLinux联盟 # Please check paths before use. YBFLinux联盟 YBFLinux联盟 # FastCGI PHP binary YBFLinux联盟 FPHPBIN=/usr/local/php/bin/php YBFLinux联盟 YBFLinux联盟 # Location to place semaphore YBFLinux联盟 SEMFILE=/tmp/php.pid YBFLinux联盟 PHP_FCGI_CHILDREN=100 YBFLinux联盟 PHP_FCGI_MAX_REQUESTS=1000 YBFLinux联盟 export PHP_FCGI_CHILDREN YBFLinux联盟 export PHP_FCGI_MAX_REQUESTS YBFLinux联盟 YBFLinux联盟 # This is Linux - use /proc to increase the local (ephemeral) port range YBFLinux联盟 #echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range YBFLinux联盟 YBFLinux联盟 if [ -z "$ZEUSHOME" ] YBFLinux联盟 then YBFLinux联盟 cd `dirname $0`/.. YBFLinux联盟 ZEUSHOME=`pwd` YBFLinux联盟 export ZEUSHOME YBFLinux联盟 fi YBFLinux联盟 YBFLinux联盟 case "$1" in YBFLinux联盟 'start') YBFLinux联盟 YBFLinux联盟 if [ -e $SEMFILE ] YBFLinux联盟 then YBFLinux联盟 echo FastCGI PHP error: already running.Restart FastCGI PHP now YBFLinux联盟 kill `cat $SEMFILE` YBFLinux联盟 sleep 5 YBFLinux联盟 fi YBFLinux联盟 YBFLinux联盟 if [ ! -x $FPHPBIN ] YBFLinux联盟 then YBFLinux联盟 echo FastCGI PHP error: please check that $FPHPBIN is executable and exists. YBFLinux联盟 exit 1 YBFLinux联盟 fi YBFLinux联盟 YBFLinux联盟 echo Starting FastCGI PHP. YBFLinux联盟 $ZEUSHOME/web/bin/fcgirunner --user=65534 --group=65534 --pidfile=$SEMFILE 8002 $FPHPBIN YBFLinux联盟 ;; YBFLinux联盟 YBFLinux联盟 'stop') YBFLinux联盟 if [ -e $SEMFILE ] YBFLinux联盟 then YBFLinux联盟 echo Stopping FastCGI PHP. YBFLinux联盟 kill `cat $SEMFILE` YBFLinux联盟 rm $SEMFILE YBFLinux联盟 exit 0 YBFLinux联盟 fi YBFLinux联盟 ;; YBFLinux联盟 'restart') YBFLinux联盟 if [ -e $SEMFILE ] YBFLinux联盟 then YBFLinux联盟 echo Stopping FastCGI PHP. YBFLinux联盟 kill `cat $SEMFILE` YBFLinux联盟 sleep 5 YBFLinux联盟 fi YBFLinux联盟 echo Starting FastCGI PHP. YBFLinux联盟 $ZEUSHOME/web/bin/fcgirunner --user=65534 --group=65534 --pidfile=$SEMFILE 8002 $FPHPBIN YBFLinux联盟 ;; YBFLinux联盟 *) YBFLinux联盟 echo "usage: $0 {start|stop|restart}" YBFLinux联盟 ;; YBFLinux联盟 YBFLinux联盟 esac YBFLinux联盟 exit 1 YBFLinux联盟 YBFLinux联盟 在这个脚本中有以下内容需要视系统情况而 修改: YBFLinux联盟 YBFLinux联盟 FPHPBIN=/usr/local/php/bin/php 应设置为php的路径 YBFLinux联盟 SEMFILE=/tmp/php.pid 生成php.pid的路径,该目录必须可写 YBFLinux联盟 PHP_FCGI_CHILDREN=100 php进程数目 YBFLinux联盟 PHP_FCGI_MAX_REQUESTS=1000 每个php的进程在退出前能够响应的请求数,用于释放资源 上面两个根据硬件配置和网站访问量设置,默认值是8,500。 一般来说 PHP_FCGI_CHILDREN > 访问并发最大值+10 YBFLinux联盟 PHP_FCGI_MAX_REQUESTS 如果设置过小,访问量大的网站会因为php进程重起频繁增加负荷。 YBFLinux联盟 #echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range 只用于linux YBFLinux联盟 --user=65534 --group=65534 为php进程运行的用户和组,一般设置为nobody用户和组FreeBSD是65534/65534,Linux是99/99 YBFLinux联盟 最后,将S05php文件设置为可执行文件,并将FastCGI/PHP运行起来: YBFLinux联盟 YBFLinux联盟 chmod 755 S05php YBFLinux联盟 ./S05php start YBFLinux联盟 一但启动后就会在ps -ax列表中显示出PHP_FCGI_CHILDREN+1个php进程。 YBFLinux联盟 到你的vhost对应的Docroot目录中建一个info.php文件,内容为: YBFLinux联盟 <? YBFLinux联盟 phpinfo(); YBFLinux联盟 ?> YBFLinux联盟 使用浏览器访问vhost中的info.php文件,应该就可以看到PHP的info页面了。 YBFLinux联盟 YBFLinux联盟 YBFLinux联盟 YBFLinux联盟 附注 YBFLinux联盟 感谢CCF的坛主hunreal写出的S05php脚本,它真的非常好用! YBFLinux联盟 如果还有什么想了解的可以到 Zeus PHP支持 页得到更多的信息。 YBFLinux联盟 YBFLinux联盟 注:任何转载或摘抄请注明文章出处(中文FreeBSD用户组 http://www.cnfug.org) YBFLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论 |
|
|
|
|
|