# Can't save pid file for php fastcgi during boot



## solshark (Feb 11, 2009)

Hello.
I'm trying to setup nginx + php + fastcgi on FreeBSD 7.1
My problem - during server booting process php-cgi starts correclty (from correct user) so on , but pid-file is empty.
If I start dbphp_fastcgi from shell - all works fine and pid stored in pid-file. Directory */var/run/dbphp_fastcgi* owned by user phpmyadmin and has 755 mode.
Any advice?


I'm using following script for start fxgi process:

*/usr/local/etc/rc.d/dbphp_fastcgi:*

```
#!/bin/sh
# PROVIDE: dbphp_fastcgi
# REQUIRE: DAEMON
# BEFORE:  LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="dbphp_fastcgi"
rcvar=`set_rcvar`

load_rc_config $name

: ${dbphp_fastcgi_enable="NO"}
: ${dbphp_fastcgi_user="www"}
: ${dbphp_fastcgi_bindaddr="127.0.0.1"}
: ${dbphp_fastcgi_bindport="9000"}
: ${dbphp_fastcgi_children="5"}
: ${dbphp_fastcgi_max_requests="1000"}
: ${dbphp_fastcgi_allowed_env=""}

export PHP_FCGI_CHILDREN=${dbphp_fastcgi_children}
export PHP_FCGI_MAX_REQUESTS=${dbphp_fastcgi_max_requests}

command="/usr/local/bin/php-cgi"
command_args="-q -b ${dbphp_fastcgi_bindaddr}:${dbphp_fastcgi_bindport} &"
pidfile="/var/run/dbphp_fastcgi/${name}.pid"

_allowed_env="ORACLE_HOME PATH USER PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
_allowed_env="${_allowed_env} ${dbphp_fastcgi_allowed_env}"

start_precmd="${name}_start_precmd"
start_postcmd="ps -U ${dbphp_fastcgi_user} -o 'pid,command'|grep ${command}|head -1|awk -- '{print \$1}' > ${pidfile}"


dbphp_fastcgi_start_precmd()
{
    touch $pidfile
    chown $dbphp_fastcgi_user $pidfile
    export USER=${dbphp_fastcgi_user}
    E=  
    for i in ${_allowed_env}; do
        eval _val="\$$i"
        if [ "${_val}_x" != "_x" ]; then
            eval _add="$i=$_val"
            E="${E} ${_add}"
        fi  
    done
    command="env - ${E} ${command}"
}

stop_postcmd=dbphpstop_postcmd

dbphpstop_postcmd()
{
    rm -f $pidfile
} 

load_rc_config $name

run_rc_command "$1"
```

*/etc/rc.conf:*

```
dbphp_fastcgi_enable="YES"
dbphp_fastcgi_user="phpmyadmin"
dbphp_fastcgi_bindaddr="127.0.0.1"
dbphp_fastcgi_bindport="9000"
dbphp_fastcgi_children="5"
dbphp_fastcgi_max_requests="1000"
dbphp_fastcgi_allowed_env=""
```


----------

