ISPConfig overlooks second instance of php-fpm & fastcgi

Discussion in 'Installation/Configuration' started by bob50, Sep 26, 2016.

  1. bob50

    bob50 New Member

    Hello members,

    Following multiple php (php-fpm & phpfastcgi) with ispconfig tutorial, I have compiled php-5.5.38 as php-fpm on ububtu 16 running with ispconfig 3.0.x . log /opt/php-5.5.38/var/log/php-fpm.log shows that it is loaded successfully

    fpm is running, pid 13606
    ready to handle connection


    . But the web instance only calling the default php7 . I have also compile phpfcgi but no luck. Already configure the php-fpm & fastcgi at additional php section at ISPConfig and available at client section. Please advice how to make the compiled php work with ISPConfig.
     
  2. bob50

    bob50 New Member

    Don't know the logic, but making all clients point to the compiled php-fpm now works. But this is not a solution at all, as users have their own choice of php version. Maybe associated, others domain calls the index.php of the very first web instance. Observed by phpinfo, others domain include the first instance in open_basedir, though at webdomain->options->open_basedir only points to associated web folder. Confused !! Can any one suggest ?
     
  3. Jesse Norell

    Jesse Norell Active Member

    In your PHP-FPM settings you have a `Path to the PHP-FPM pool directory` - in that directory there should be a separate config file for each website using this php version; it sounds like your php daemon isn't looking at/finding those. Maybe run through all your setup again, something obviously isn't right. I setup a couple php versions for debian 8, with a few minor modifications but largely following the tutorials, so they should work. If you don't find anything yourself, maybe post the commands you used to compile the php versions, as well as the settings from Additional PHP Versions tabs and maybe your init script/systemd unit file.
     
    Last edited: Sep 26, 2016
  4. bob50

    bob50 New Member

    Hi Jesse,

    Thanks for your valuable suggestion. The setting is
    php-fpm init path - /etc/init.d/php-fpm-5.3
    php.ini path - /opt/php-5.3/lib
    php-fpm pool - /opt/php-5.3/etc/pool.d

    pool directory do have configuration file for clients like web1.conf , web2.conf etc...
    But the problem is , though web1 & web2 configured with php-fpm version 5.3 , the conf files in pool.d points php7

    [web1]
    listen = /var/lib/php7.0-fpm/web1.sock
    listen.owner = web1

    [web2]
    listen = /var/lib/php7.0-fpm/web2.sock
    listen.owner = web2

    while the phpinfo in domain shows php5 as version. CONFUSING !!

    /opt/php-5.3/etc/php-fpm.conf has following
    include=/opt/php-5.3/etc/pool.d/*.conf
    pid = run/php-fpm.pid
    listen = 127.0.0.1:9000

    I am clueless, please suggest how to fix this issue.
     
  5. bob50

    bob50 New Member

    there is also /etc/apache2/conf-available/php7.0-fpm.conf

    <IfModule !mod_php7.c>
    # Enable http authorization headers
    SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    <FilesMatch ".+\.ph(p[3457]?|t|tml)$">
    SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
    </FilesMatch>
    <FilesMatch ".+\.phps$">
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Require all denied
    </FilesMatch>
    # Deny access to files without filename (e.g. '.php')
    <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
    Require all denied
    </FilesMatch>
    </IfModule>
     
  6. Jesse Norell

    Jesse Norell Active Member

    In your first post you have php-5.5.38 installed under /opt/php-5.5.38/, but then you're using /opt/php-5.3/ in your additional php settings. Go back through the tutorial and make everything consistent - check the paths in all your commands to compile php, check your settings, and check all paths in your init script/systemd unit files.
     
  7. bob50

    bob50 New Member

    Hi Jesse,

    thanks for your kind response. You are correct, I provided the php-5.3 config which I compiled recently.
    But here we are discussing php-5.5.38 settings. Sites are configured with this php-5.5.38 & not with php-5.3

    Path to the PHP-FPM init script´┐╝/etc/init.d/php-5.5.38-fpm
    Path to the php.ini directory´┐╝/opt/php-5.5.38/lib
    Path to the PHP-FPM pool directory´┐╝/opt/php-5.5.38/etc/pool.d


    similarly init path /etc/init.d/php-5.5.38-fpm having config
    php_fpm_BIN=/opt/php-5.5.38/sbin/php-fpm
    php_fpm_CONF=/opt/php-5.5.38/etc/php-fpm.conf
    php_fpm_PID=/opt/php-5.5.38/var/run/php-fpm.pid


    Please advise.
     
  8. Jesse Norell

    Jesse Norell Active Member

    I think that's ok, actually, as I noticed a similar situation in debian8, I think that just puts the communication socket in the "wrong" directory, but both the php daemon and website config files pointed to the same path. For debian 8 the system php version is 5.6.24, and all the .sock files for websites get put under /var/lib/php5-fpm/, even for sites running php7 or a different php5 version. It might be nice (and worth an rfe?) to have a different path that doesn't include a php version in the name, but functionally it does not matter.

    I assume there are a lot more settings in the individual /opt/php-{version}/etc/pool.d/web#.conf files? There should be, including the open_basedir setting you mention above at https://www.howtoforge.com/communit...nstance-of-php-fpm-fastcgi.74054/#post-348328

    In comment #1 and #2 you had different behavior/symptoms, where are things at right now? Maybe pick one specific site, go make absolutely certain it is set to the php mode and version you think it is (eg. often I change it as the client, but the change does not take effect, as I accidentally saved as a reseller earlier, so "client protection mode" is in effect, and it silently fails to change settings), then post the full config files /opt/php-#/etc/php-fpm.conf and /opt/php-#/etc/pool.d/web#.conf as I don't see anything wrong right offhand, and of course am assuming a little of it is correct.

    Another thought worth checking out is that the init script is getting run right, as maybe it's simply that the php daemon isn't getting restarted when it should. I think some folks have had a mixup of init.d/systemd config that caused problems. Try 'lsof /var/lib/php7.0-fpm/web#.sock' and you should see that php-fpm daemon is listening on each socket.
     
  9. bob50

    bob50 New Member

    Hi Jesse,

    Thanks for your advise. Meanwhile I have completely removed php5.3 from server as well as from ispconfig to avoid further confusion. Now we have default php-7 & compiled php-5.5.38 (php-fpm & fastcgi).

    I'm working as admin now in ispconfig


    The client sites are configured with php-5.5.38, to be sure I make the site use default php and this remove web1.conf from pool.d ; then again reconfiguration with php-fpm version 5.5.38 . web1.conf recreated.

    /opt/php-5.5.38/etc/pool.d/web1.conf (here I purposely replace hostname with xxxx)

    [web1]
    listen = /var/lib/php7.0-fpm/web1.sock
    listen.owner = web1
    listen.group = www-data
    listen.mode = 0660

    user = web1
    group = www-data

    pm = dynamic
    pm.max_children = 10
    pm.start_servers = 2
    pm.min_spare_servers = 1
    pm.max_spare_servers = 5
    pm.max_requests = 0

    chdir = /

    env[HOSTNAME] = $HOSTNAME
    env[TMP] = /var/www/clients/client1/web1/tmp
    env[TMPDIR] = /var/www/clients/client1/web1/tmp
    env[TEMP] = /var/www/clients/client1/web1/tmp
    env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    php_admin_value[open_basedir] = /var/www/clients/client1/web1/web:/var/www/clients/client1/web1/private:/var/www/clients/client1/web1/tmp:/var/www/xxxx.com/web:/srv/www/xxxxx.com/web:/usr/share/php5:/usr/share/php:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin
    php_admin_value[session.save_path] = /var/www/clients/client1/web1/tmp
    php_admin_value[upload_tmp_dir] = /var/www/clients/client1/web1/tmp
    php_admin_value[sendmail_path] = "/usr/sbin/sendmail -t -i -f [email protected]"


    only after starting /etc/init.d/php-5.5.38-fpm , following shows results and NOT WHEN default php7-fpm is running alone.
    # lsof /var/lib/php7.0-fpm/web1.sock
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    php-fpm 5322 root 8u unix 0xffff880fe72b8000 0t0 1927586 /var/lib/php7.0-fpm/web1.sock type=STREAM
    php-fpm 5323 web1 0u unix 0xffff880fe72b8000 0t0 1927586 /var/lib/php7.0-fpm/web1.sock type=STREAM
    php-fpm 5324 web1 0u unix 0xffff880fe72b8000 0t0 1927586 /var/lib/php7.0-fpm/web1.sock type=STREAM

    As you can see the no index.php is preset at web directory of this site
    # ls /var/www/clients/client1/web1/web
    favicon.ico index.html __info.php info.php robots.txt stats

    But when called by domain, a index.php is called which is belongs to another site/domain
    /var/www/clients/client3/web2/web/index.php
    STRANGE !!

    for your inspection here is /etc/init.d/php-5.5.38-fpm init script

    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: php-5.5.38-fpm
    # Required-Start: $all
    # Required-Stop: $all
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: starts php-5.5.38-fpm
    # Description: starts the PHP FastCGI Process Manager daemon
    ### END INIT INFO
    php_fpm_BIN=/opt/php-5.5.38/sbin/php-fpm
    php_fpm_CONF=/opt/php-5.5.38/etc/php-fpm.conf
    php_fpm_PID=/opt/php-5.5.38/var/run/php-fpm.pid
    php_opts="--fpm-config $php_fpm_CONF"

    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"
    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

    and
    grep -v ";" /opt/php-5.5.38/etc/php-fpm.conf

    include=/opt/php-5.5.38/etc/pool.d/*.conf

    [global]
    pid = run/php-fpm.pid

    [www]
    user = www-data
    group = www-data

    listen = 127.0.0.1:9000
    pm = dynamic
    pm.max_children = 5
    pm.start_servers = 2
    pm.min_spare_servers = 1
    pm.max_spare_servers = 3

    ps -efH | grep php is showing following

    root 29814 32348 0 15:42 pts/1 00:00:00 grep --color=auto php
    ispconf+ 26967 20204 0 15:38 ? 00:00:00 /usr/bin/php-cgi -d disable_classes= -d disable_functions= -d magic_quotes_gpc=off -d open_basedir= -d session.save_path=/usr/local/ispconfig/interface/temp
    ispconf+ 26968 26967 0 15:38 ? 00:00:00 /usr/bin/php-cgi -d disable_classes= -d disable_functions= -d magic_quotes_gpc=off -d open_basedir= -d session.save_path=/usr/local/ispconfig/interface/temp
    root 28497 1 0 15:40 ? 00:00:00 php-fpm: master process (/opt/php-5.5.38/etc/php-fpm.conf)
    web1 28498 28497 0 15:40 ? 00:00:00 php-fpm: pool web1
    web1 28499 28497 0 15:40 ? 00:00:00 php-fpm: pool web1
    www-data 28500 28497 0 15:40 ? 00:00:00 php-fpm: pool www
    www-data 28501 28497 0 15:40 ? 00:00:00 php-fpm: pool www

    Now if I restart both the php-fpm again , it shows different ( php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf) now added ). and sites configured with php-fpm 5.5.38 goes back to default php7 as witnessed by phpinfo.

    ps -efH | grep php
    root 11540 32348 0 16:02 pts/1 00:00:00 grep --color=auto php
    ispconf+ 6551 6542 0 15:55 ? 00:00:00 /usr/bin/php-cgi -d disable_classes= -d disable_functions= -d magic_quotes_gpc=off -d open_basedir= -d session.save_path=/usr/local/ispconfig/interface/temp
    ispconf+ 6552 6551 0 15:55 ? 00:00:00 /usr/bin/php-cgi -d disable_classes= -d disable_functions= -d magic_quotes_gpc=off -d open_basedir= -d session.save_path=/usr/local/ispconfig/interface/temp
    root 9108 1 0 15:59 ? 00:00:00 php-fpm: master process (/opt/php-5.5.38/etc/php-fpm.conf)
    web1 9109 9108 0 15:59 ? 00:00:00 php-fpm: pool web1
    web1 9110 9108 0 15:59 ? 00:00:00 php-fpm: pool web1
    www-data 9111 9108 0 15:59 ? 00:00:00 php-fpm: pool www
    www-data 9112 9108 0 15:59 ? 00:00:00 php-fpm: pool www
    root 10899 1 0 16:01 ? 00:00:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
    web2 10901 10899 0 16:01 ? 00:00:00 php-fpm: pool web2
    web2 10902 10899 0 16:01 ? 00:00:00 php-fpm: pool web2
    www-data 10903 10899 0 16:01 ? 00:00:00 php-fpm: pool www
    www-data 10904 10899 0 16:01 ? 00:00:00 php-fpm: pool www

    Will it help if I install ispconfig with multiple php on debian 8 ?
     
    Last edited: Sep 28, 2016
  10. Jesse Norell

    Jesse Norell Active Member

    In your init script, change:
    Code:
    # Required-Start:    $remote_fs $network
    # Required-Stop:     $remote_fs $network
    Did you create a systemd unit file? Ie. /lib/systemd/system/php-5.5.38-fpm.service should look like this from the example (https://www.howtoforge.com/tutorial/how-to-install-php-7-on-debian/):
    Code:
    [Unit]
    Description=The PHP 5.5.38 FastCGI Process Manager
    After=network.target
    
    [Service]
    Type=simple
    PIDFile=/opt/php-5.5.38/var/run/php-fpm.pid
    ExecStart=/opt/php-5.5.38/sbin/php-fpm --nodaemonize --fpm-config /opt/php-5.5.38/etc/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    Then run
    Code:
    systemctl enable php-5.5.38-fpm.service
    systemctl daemon-reload
    Try stopping the init script and starting the systemd service:
    Code:
    /etc/init.d/php-5.5.38-fpm start
    systemctl start php-5.5.38-fpm.service
    And see what that gets you. I had a problem with changing/starting/stopping daemons until I realized I was mixing init.d and systemd commands (on the cli).

    Where do you see that called, apache logs? Would you have mixed using the ip address one some sites and '*' on other sites?
     
  11. bob50

    bob50 New Member

    Hi Jesse,
    Here is a positive development. After being stick with numeric IP address ( and not *) to all clients the sites are reflecting proper php version. Have not written the systemd script, but settings are working even after server reboot. I don't have enough words to thank you and interested to know how IP address field affects the behavior ?
     
  12. Jesse Norell

    Jesse Norell Active Member

    It affects which vhosts are considered when the web server finds the best match for a request. If you use an ip address for any site, then all requests that come in on that ip address will only match vhosts which have an ip address set - any vhosts using '*' are not even considered for that request.
     

Share This Page