项目

通用

个人资料

操作

FreeBSD 中便捷的外部FastCGI PHP进程生成

所附脚本对 FreeBSD 用户来说应该非常方便。这是一个用于生成 FastCGI PHP 进程的 rc.d 脚本。它基于 Lighttpd 源码中 `doc/` 目录下的 "spawn-php.sh":source:tags/lighttpd-1.4.8/doc/spawn-php.sh。

安装

只需将 fastcgi-php.sh 复制到 `/usr/local/etc/rc.d/`。然后

# cd /usr/local/etc/rc.d/
# chown root:wheel fastcgi-php.sh
# chmod 544 fastcgi-php.sh
# mkdir /var/run/fcgiphp
# chown www:www /var/run/fcgiphp

您应该将最后一行的 `www:www` 替换为 FastCGI 运行的用户:组(参见下面配置中的 fcgiphp_userfcgiphp_group)。

配置

以下是配置参数及其默认值,您可以在 `/etc/rc.conf` 中更改它们

fcgiphp_enable="NO"                      # enable FastCGI+PHP
fcgiphp_bin_path="/usr/local/bin/php"    # absolute path to the PHP binary
fcgiphp_user="www"                       # switch to user
fcgiphp_group="www"                      # switch to group
fcgiphp_children="10"                    # number of PHP childs to spawn
fcgiphp_port="8002"                      # bind to tcp-port on localhost
fcgiphp_socket="/tmp/php-fastcgi.sock"   # bind to unix domain socket
fcgiphp_env="SHELL PATH USER"            # allowed environment variables separated by spaces
fcgiphp_max_requests="500"               # number of request server by a single php-process until is will be restarted
fcgiphp_addr="localhost"                 # adresses where PHP should access server connections from

要使脚本正常工作,您只需调整一件事

fcgiphp_enable="YES" 

对于 FreeBSD 中当前版本的 php4 和 php5 端口,您在构建 PHP 端口时必须启用“Build CGI version”选项。PHP 二进制文件的 CGI 版本现在被称为“php-cgi”。在这种情况下,您需要在 /etc/rc.conf 中进行以下更改

fcgiphp_bin_path="/usr/local/bin/php-cgi" 

请注意,socket 的优先级高于 port。如果您想绑定到 TCP 端口,则必须取消设置 socket 参数

fcgiphp_socket="" 
fcgiphp_port="8002" 

控制

现在您可以

# /usr/local/etc/rc.d/fastcgi-php.sh start
Starting fcgiphp.
# /usr/local/etc/rc.d/fastcgi-php.sh stop
Stopping fcgiphp.
# /usr/local/etc/rc.d/fastcgi-php.sh restart
Stopping fcgiphp.
Starting fcgiphp.

兼容性

该脚本仅在 FreeBSD 6.0 下测试过,但它应该能在任何现代 FreeBSD 系统上运行。

davojan 更新于 大约 13 年 前 · 14 次修订