跳至主要内容

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.

评论

此博客中的热门博文

My childhood

"Each person's life is like a book; some people prefer to savor it slowly, while others like to gradually forget it. Looking back, I want to see if I can discern the trajectory of the world from my seemingly insignificant life. I am a child from the countryside, and perhaps most people cannot understand what my so-called countryside looks like. Indeed, the impressions of the countryside can be very different depending on the country, and moreover, more than 40 years have passed, during these 40 years of rapid development in China. A phrase suddenly comes to mind, 'I see him building tall buildings, I see him feasting, I see everything collapsing.' The place where I was born is a small town in the southwest of China, a town so small that it only has one street, and the widest part is only 3 meters. Paved with stone slabs, worn by many years of use, the slabs are not flat but rather filled with small bumps and hollows, yet strangely smooth. At the end of the street is a ...

youtube script covid

[INTRO - Soft Music Playing] Narrator: "In August 2020, during the COVID-19 pandemic in China, I experienced a series of events that revealed the overbearing, unreasonable, and ignorant aspects of government policies. This story unfolds my observations and experiences in Xinjiang since April, presented in a neutral and factual manner." [Scene Transition - Music Shifts to a More Reflective Tone] Narrator: "April 8th marked the end of my nearly three-month-long home quarantine in Wuhan, as the lockdown was finally lifted. With Xinjiang gradually reopening since March, my work required me to return there as soon as possible." [Visuals: Scenes of Empty Streets in Wuhan, Transitioning to Busy Airports] Narrator: "My journey back to Xinjiang was fraught with delays. The direct flight on China Southern Airlines kept getting postponed. Reluctantly, I had to transit through Xi'an. Before leaving, I reported my health status to the community in Changji City, where I ...

survilliance in china

  Hello everyone, welcome to my YouTube channel. This is my first video, and I'm very happy to meet you all. I come from China, and looking back, time has passed so quickly. I've been in France for almost 20 years. Sometimes, when I chat with friends, I'm surprised at how little the French know about China. What's even more alarming is that the French media follows the narrative of the Chinese official media. This is why I decided to create a YouTube channel to talk to my French friends about the China I know. Since my parents and friends are still in China, and to avoid unnecessary impact on their lives, I've decided not to appear in person for now. This is how I fulfill my long-standing wish. My first episode is about "Digital Surveillance in China.",  Digital Surveillance: In China, using the official App Store is mandatory. Apple's App Store is China-specific, and all data is stored there. Google's App Store is simply inaccessible in China. If ...