Project

General

Profile

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

Revision 1 (davojan, 2006-05-11 16:46) → Revision 2/14 (davojan, 2006-05-15 12:01)

The script attached should be very handy for {{{ 
 #!/bin/sh 
 #    FreeBSD users. This is rc.d script to spawn FastCGI PHP processes. It is based on [source:tags/lighttpd-1.4.8/doc/spawn-php.sh spawn-php.sh] from doc/ directory for fastcgi+php 
 #    in the lighttpd sources. 

 == Installing == rc.conf 
 Just copy [attachment:fastcgi-php.sh fastcgi-php.sh] # fcgiphp_enable (bool):     Set it to /usr/local/etc/rc.d/. Then "YES" to enable fastcgi+php 
 {{{ 
 # cd /usr/local/etc/rc.d/             Default is "NO". 
 # chown root:wheel fastcgi-php.sh other options see below 
 # chmod 544 fastcgi-php.sh 

 . /etc/rc.subr 

 name="fcgiphp" 
 }}} rcvar=`set_rcvar` 

 == Configuring == load_rc_config $name 

 : ${fcgiphp_enable="NO"} 
 Here are configuration parameters with their default values, which you can change in /etc/rc.conf: : ${fcgiphp_user="www"} 
 {{{ : ${fcgiphp_group="www"} 
 fcgiphp_enable="NO" : ${fcgiphp_children="10"} 
 fcgiphp_user="www" : ${fcgiphp_port="8002"} 
 fcgiphp_group="www" : ${fcgiphp_socket="/tmp/php-fastcgi.sock"} 
 fcgiphp_children="10" : ${fcgiphp_env="SHELL PATH USER"} 
 fcgiphp_port="8002" : ${fcgiphp_max_requests="1000"} 
 fcgiphp_socket="/tmp/php-fastcgi.sock" : ${fcgiphp_addr="localhost"} 


 pidfile=/var/run/fcgiphp/fcgiphp.pid 
 fcgiphp_env="SHELL PATH USER" procname="/usr/local/bin/php" 
 fcgiphp_max_requests="500" command_args="/usr/local/bin/spawn-fcgi 2> /dev/null -f /usr/local/bin/php -s ${fcgiphp_socket} -u ${fcgiphp_user} -g ${fcgiphp_group} -C ${fcgiphp_children} -P ${pidfile}" 
 fcgiphp_addr="localhost" start_precmd=start_precmd 
 }}} stop_postcmd=stop_postcmd 

 start_precmd() 
 To make script workable you { 
    PHP_FCGI_MAX_REQUESTS="${fcgiphp_max_requests}" 
    FCGI_WEB_SERVER_ADDRS=$fcgiphp_addr 
    export PHP_FCGI_MAX_REQUESTS 
    export FCGI_WEB_SERVER_ADDRS 
    allowed_env="${fcgiphp_env} PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS" 
 # copy the allowed environment variables 
    E="" 
    for i in $allowed_env; do 
       eval "x=\$$i" 
       E="$E $i=$x" 
    done 
    command="env - $E" 

    if [ -n $fcgiphp_socket ]; then 
       command_args="${command_args} -s ${fcgiphp_socket}" 
    elif [ -n "${fcgiphp_port}" ]; then 
       command_args="${command_args} -p ${fcgiphp_port}" 
    else 
       echo "socket or port must adjust only one thing: be specified!" 
       exit 
    fi 
 {{{ } 

 stop_postcmd() 
 fcgiphp_enable="YES" { 
    rm -f ${pidfile} 
    eval "ipcs | awk '{ if (\$5 == \"${fcgiphp_user}\") print \"ipcrm -s \"\$2}' | /bin/sh" 
 } 

 run_rc_command "$1" 
 }}}