Project

General

Profile

Fastcgi-php-starter-for-freebsd » History » Revision 12

Revision 11 (Anonymous, 2006-10-24 23:06) → Revision 12/14 (davojan, 2008-10-09 21:24)

h1. Handy External Spawning FastCGI PHP Processes in FreeBSD 

 

 The script attached should be very handy for FreeBSD users. This is rc.d script to spawn FastCGI PHP processes. It is based on "spawn-php.sh":source:tags/lighttpd-1.4.8/doc/spawn-php.sh from `doc/` directory in the lighttpd sources. 


 


 h2. Install 

 

 Just copy [[lighttpd:attachment:fastcgi-php.sh|fastcgi-php.sh]] to `/usr/local/etc/rc.d/`. Then 

 

 <pre> 

 #!ShellExample 
 # 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 
 </pre> 

 

 You should replace `www:www` in the last line with your user:group which FastCGI will run under (see @fcgiphp_user@ and @fcgiphp_group@ in configuration below). 


 


 h2. Configure 

 

 Here are configuration parameters with their default values, which you can change in `/etc/rc.conf`: 

 <pre><code class="sh"> 

 <pre> 

 #!sh 
 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 
 </code></pre> 

 </pre> 

 To make script workable you must adjust only one thing: 

 <pre><code class="sh"> 

 <pre> 

 #!sh 
 fcgiphp_enable="YES" 
 </code></pre> 

 </pre> 

 With current versions of the php4 and php5 ports from FreeBSD, you must enable "Build CGI version" when building the PHP port. The CGI version of the PHP binary is now called "php-cgi". In this case, you need to make the following change in /etc/rc.conf: 

 <pre><code class="sh"> 
 

 <pre> 

 fcgiphp_bin_path="/usr/local/bin/php-cgi" 
 </code></pre> 

 </pre> 

 Note, that @socket@ has more priority than @port@. If you want to bind to TCP-port you must unset socket parameter: 

 <pre><code class="sh"> 

 <pre> 

 #!sh 
 fcgiphp_socket="" 
 fcgiphp_port="8002" 
 </code></pre> 


 </pre> 



 h2. Control 

 

 Now you can: 

 

 <pre> 

 #!ShellExample 
 # /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. 
 </pre> 


 



 h2. Compatibility 

 

 The script was tested only under FreeBSD 6.0, but it should run under any modern FreeBSD system.