跳至主要内容

install god dame fastgci and fpm on our server.

first of all, need to create a child process of CGI which located in /etc/init.d/php-common-Perso.sh

prefix="/opt/php-5.3.6-full";
exec_prefix=${prefix};

php_fpm_BIN="${exec_prefix}/sbin/php-fpm";
php_fpm_CONF="/home/siteadm/common/php/Perso.conf";
php_fpm_PID="/home/siteadm/common/php/Perso.pid";
php_fpm_INI="/home/siteadm/common/php/Perso.ini";
PHP_INI_SCAN_DIR="/home/siteadm/common/php/vhost";

php_opts="--fpm-config $php_fpm_CONF -c $php_fpm_INI"

export PHP_INI_SCAN_DIR;

. /home/siteadm_admin/template/php/php-fpm-init.sh

the PHP_INI_SCAN_DIR include all specification of fpm for each virtual host of apache:
[HOST=main.addepi.fr]
open_basedir = "/data/admin/"
doc_root = "/data/admin/web"
mail.log = "/data/admin/app/logs/php.mail.error.log"
short_open_tag = 1
error_log = "/data/admin/app/logs/php.error.log"
default_charset = "utf-8"

and some other package loader like imagick.ini
; configuration for php imagick module
extension=imagick.so

In fact, Perso.conf is still another php.ini for php-fpm, it contains only three lines:
pid = /home/siteadm/common/php/Perso.pid
error_log = /home/siteadm/common/log/php-Perso_error.log
include=/home/siteadm/common/php/Perso/*.conf
which is all the child fastcgi defination, here i add a /home/siteadm/common/php/Perso/main-php-default.conf file with:
[main-default]

catch_workers_output            = yes

listen                                          = /home/siteadm/common/php/Perso/main-php-default.sock
listen.owner                            = root
listen.group                            = hosts
listen.mode                                     = 0660

user                                            = www-data ; normalement nobody
group                                           = hosts

;chroot                                         = /data/admin

pm                                                      = dynamic

pm.max_children                         = 10
pm.start_servers                        = 1
pm.min_spare_servers            = 1
pm.max_spare_servers            = 2
pm.max_requests                         = 500

pm.status_path                          = /fpm-status
ping.path                                       = /fpm-ping
ping.response                           = pong

;slowlog                                                = {LOG_ROOT}/php-main_slow.log
;request_slowlog_timeout                = 5s

; Variables d'environnement
env[TMP]                                        = /data/temp
env[TMPDIR]                                     = /data/temp
env[TEMP]                                       = /data/temp

; Directives de configuration bloquées
;php_admin_flag[param1] = on
php_admin_value[open_basedir] = "/data/admin"
php_admin_value[error_log] = "/data/admin/app/logs/php.error.log"
php_admin_value[mail.log] = "/data/admin/app/logs/php.mail.error.log"
php_admin_value[upload_tmp_dir] = "/data/temp"
php_admin_value[session.save_path] = "/data/temp"
php_admin_value[apc.stat] = "0"
php_admin_value[apc.lazy_functions] = "0"
php_admin_value[apc.lazy_classes] = "0"


in this file, we define all the parameter of this child fastcgi process parameter. include his sock file, user, group temp folder etc. After we done this, need to launch the php-common-Perso.sh, which is also launching /home/siteadm_admin/template/php/php-fpm-init.sh contained by this .sh
wait_for_pid () {
        try=0

        while test $try -lt 35 ; do

                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;

                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac

                echo -n .
                try=`expr $try + 1`
                sleep 1

        done

}

case "$1" in
        start)
                echo -n "Starting php-fpm "

                $php_fpm_BIN $php_opts

                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi

                wait_for_pid created $php_fpm_PID

                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;

        stop)
                echo -n "Gracefully shutting down php-fpm "

                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi

                kill -QUIT `cat $php_fpm_PID`

                wait_for_pid removed $php_fpm_PID

                if [ -n "$try" ] ; then
                        echo " failed. Use force-exit"
                        exit 1
                else
                        echo " done"
                fi
        ;;

        force-quit)
                echo -n "Terminating php-fpm "

                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi

                kill -TERM `cat $php_fpm_PID`

                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;

        restart)
                $0 stop
                $0 start
        ;;

        reload)

                echo -n "Reload service php-fpm "

                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi

                kill -USR2 `cat $php_fpm_PID`

                echo " done"
        ;;

        *)
                echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                exit 1
        ;;

esac

So , we can start our fpm main and child process. and if we type: ps aux | grep main, we should see :
www-data 24417  0.0  0.9 346424 76508 ?        S    Dec03   0:03 php-fpm: pool main-default 
Well, from now we can use this as an external fastcgi socket. so i create an vhost like this: /etc/apache2/sites-available/main
FastCGIExternalServer /data/admin/cgi-bin/php-default -socket /home/siteadm/common/php/Perso/main-php-default.sock -pass-header Authorization

        DocumentRoot "/data/admin/web"
        ServerName main.addepi.fr
        ServerAlias main.addepi.fr
        ServerAdmin webmaster@addepi.fr
        CustomLog /data/admin/app/logs/apache.access.log combined
        ErrorLog /data/admin/app/logs/apache.error.log
        ScriptAlias /cgi-bin/ /data/admin/cgi-bin/
        Action php-fpm /cgi-bin/php-default

       order allow,deny
       allow from all
       DirectoryIndex app.php
       AddHandler php-fpm .php
       Options -Indexes


        Order allow,deny
        Allow from env=REDIRECT_STATUS




well, you really do not need a file name: /data/admin/cgi-bin/php-default this is an alias of the socket name.
relaunch the apache2, we can visit main.addepi.fr now.

评论

此博客中的热门博文

jquery on 的问题

return false  from  within a jQuery event handler  is effectively the same as calling both  e.preventDefault and  e.stopPropagation  on the passed  jQuery.Event object. e.preventDefault()  will prevent the default event from occuring,  e.stopPropagation()  will prevent the evet from bubbling up and  return false  will do both. Note that this behaviour differs from  normal  (non-jQuery) event handlers, in which, notably,  return false   does  not  stop the event from bubbling up . 所以on前半部分的selector必须是静态的。

chrome extension Error: attempting to use a disconnected prot object

if you get this error: Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:236 chromeHidden.Port.dispatchOnDisconnect miscellaneous_bindings:236 Uncaught Error: Attempting to use a disconnected port object miscellaneous_bindings:58 PortImpl.postMessage miscellaneous_bindings:58 responseCallback miscellaneous_bindings:143 xhr.onreadystatechange That means you have make some mistake as this discussed: This is caused when a connection get closed. For example if you open a tab that has the content_script injected, it opens a connection, the tab is closed, and then the background_page tries to pass a message. It will fail because the tab is no longer active to receive the message. In your case I would guess that as tabs close and new tabs open you are attempting to post messages with the old tabId instead of creating a new connection to the new tab. I would recommend reading through the  long-lived connections s

记得很久以前,不知道是在跟谁发感慨,久到好像是上大学时候的事了。我说,我流过很多眼泪,看电影流眼泪,看小说流眼泪,听别人的故事留言了,听歌的时候流眼泪,晚上一个人的时候独自流眼泪。我似乎是一个是一个太不像男人的男人。可是我又说,这些眼泪都是为自己流的。于是我也问对面那个人,(嗯,我也记不起她是谁了): "你为别人流过眼泪么?",居然没有回答我. 也许看见这篇文章的人也不相信,但是我真的想问你一句,你为别人流过眼泪么?真真正正的是为别人的,不是可怜自己,不是觉得别人可怜而让自己也感到了可怜,仅仅是为了别人而悲伤,有过么?如果真的有,我想那也许才是爱吧。 也许您会觉得奇怪,这和爱有什么关系?是啊,流眼泪就是爱么?我们因为悲伤而流泪,流泪是因为,爱别离,求不得,这些的主体是什么?是自己。 我们都是爱自己的,只是99%的人是吧。所以我们流泪了,因为我们的那些种种原因,我们很少会因为别人“求不得,爱别离”而流泪吧。也许说,那又不是自己,对呀,你爱自己,你又不爱她,何苦要为她流这种泪? 我不是一个宽容的人,我也不是一个豁达的人,这是我一生的缺点。我们会为了爱去宽容,我们会因为爱而变的豁达,也许,这是因为我从来都没有真正的爱过谁吧,甚至,连自己。嘿,我现在都开始疑惑,我真的爱过你么,如果是,我为什么都没有宽容和豁达呢?