Problem with multiple PHP versions

Discussion in 'Installation/Configuration' started by Guido64, Feb 18, 2016.

  1. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Please run
    Code:
    apt-get install libapache2-mod-fastcgi
    a2enmod fastcgi
    service apache2 restart
    
    Maybe you will need to switch back and forth PHP-FPM in your web config but your issue here is that PHP-FPM requires fastcgi ( which is not the same as fcgi(d) ).
     
    borekon likes this.
  2. borekon

    borekon New Member

    Great! it worked!!
    i had to add
    deb http://ftp.de.debian.org/debian wheezy main non-free
    to the sources.list in order to install libapache2-mod-fastcgi
    thanks a lot!!
     
  3. Guido64

    Guido64 Member

    Sorry i didn't replied sooner.
    I didn't got a email from the website there were any new reactions.

    Anyway, I changed things the way you (and Till) advised but not so much luck on my side it is still not working.

    I saw in /var/log/ispconfig/cron.log this error:
    wo feb 24 22:53:03 CET 2016 PHP Warning: file_put_contents(/opt/php-7.0.3/etc/php-fpm/web1.conf): failed to open stream: No such file or directory in /usr/local/ispconfig/server/lib/classes/system.inc.php on line 791

    So I think I didn't set it up right. I'm starting over again tomorrow or the day after tomorrow.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Does the directory /opt/php-7.0.3/etc/php-fpm/ exist?
     
    Guido64 likes this.
  5. Guido64

    Guido64 Member

    Thank you Till.

    No that directory did not exist. In the tutorial is says: cp /opt/php-7.0.3/etc/php-fpm.d/www.conf.default /opt/php-7.0.3/etc/php-fpm.d/www.conf thats why the /opt/php-7.0.3/etc/php-fpm.d/ directory exist but not /opt/php-7.0.3/etc/php-fpm/ i changed that and tried again if switching to php7-fpm worked but it stil doesn't want to work.

    The error is gone from the cron log file except for this one: sh: chattr: opdracht niet gevonden (error not found)
    I searched the apt cache for this program but as result it gives e2fslibs. wen i install this program it tells me i already have installed the latest version of this package.
     
    Last edited: Feb 25, 2016
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Did you check that you enterd the exact paths as described in the text of the tutorial when adding the php 7 in ispconfig?
     
    Guido64 likes this.
  7. Guido64

    Guido64 Member

    Most of the time I copy/paste paths and commands from a tutorial to avoid mistakes but obviously something still went wrong. So I am going to destroy this virtual machine I used for this and start over again with a fresh ispconfig on debian 8 vps I have backed up. So I don't have to start completely over with installing Debian and ispconfig I can start right away with the php7-fpm tutorial. I pay extra attention to everything what has to be done because I really want to know what I did wrong before and I don't want to keep starting over.

    Maybe I find out what I did wrong before.
    I let you know if it worked or not.
     
  8. Guido64

    Guido64 Member

    Yess it works now :)
    Can I install older php versions like php 5.3, 5.4, 5.6 also this way on Debian 8?
     
  9. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Should be possible, absolutely - even 5.2 with fpm-patch works, wouldn't reocommend since it's been 5years+ EOL but it works
     
    Guido64 likes this.
  10. Guido64

    Guido64 Member

    Oke sweet. That is going to be my next goal. Thanks a lot for all your help! Really nice it works now.
     
  11. Guido64

    Guido64 Member

    I tried to add php 5.3.29. First i tried with the systemd way like we did php7 that did not work. Wen i switched to php5.3.29 it gave same problems as i before had with php7. Then i tried again this time with the init script instead of the systemd script. Also with the init way it does not work.

    I installed php 5.3.29 the way it is explained in this tutorial but this is not the same as we installed php7. Should i go for the systemd way or the init script way to install php 5.3.29 ?

    My goal is to install several older php versions besides the default php 5.6 and the additional php 7 wich already installed and works so i can keep my old websites running on my local ispconfig3 server.
     
  12. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    I'd go with systemd only then - mixing up things is bad, soon you're asking yourself how to restart which service :)
    What didn't work with the systemd way? Didn't it start at all? Have you adjusted the "### BEGIN INIT INFO" section aswell?
    Does php 5.3 start when manually adding / starting pool / service?
     
  13. Guido64

    Guido64 Member

    I did change the init script to 5.3.29 and php 5.3.29 does start it just doesn't want to switch. wen i open the phpinfo() page i receive the same error as i got wen we started this thread exact the same problem.

    Switching between the default and php 7 stil works perfectly now i wanted to complete my ispconfig server to add some older php version so i could keep on running some older website just for fun i want to keep them running for fun not production. and the higer php version i use for present and future websites.

    But the multiple php versions tutorial is in few things different from the php 7 tutorial and i can't get my head eround what is exactly the difference it can't be a lot different because php5.3 does start is just isn't switching.

    I would like to use systemd because thats the future i gues and i did try it the php7 way but that didn't work so i started over but then using the init script way wich also didn't work. I didn't want to ask for help again here but i have no clue how to go forward.

    I setup a fresh backup again with default php 5.6 and additional php7 working so i can start over again. Some paths are different in the php7 and mulitple versions tutorial. That confuses me and probably thats the point were it goes wrong i think.

    Would be nice if someone would write a mulitple php versions tutorial for windows 8, duh I meen Debian 8 offcourse, ispconfig servers. Including few older versions and also php7.
     
    Last edited: Mar 10, 2016
  14. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    well I'm not going to make it on windows 8 ( typo? ) - but going to try what you want to achieve on a debian 8 test system.
    I'll note down every steps and do some testing. I'll give you an update after this.
     
    Guido64 likes this.
  15. Guido64

    Guido64 Member

    haha yes windows 8 is a typo should be Debian 8 ofcourse sorry about that i wil correct that.
    Would be awesome if you would create that tutorial and you even going to send me update wen it is done geez realy great. I am looking forward to it !

    Many thanks again!
     
    Last edited: Mar 11, 2016
  16. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    OK, PHP 7 already working, note I added APCu extension. PHP 5.3 will follow shortly :)

    This is for building PHP 7.0.4 on Debian 8 using systemd for PHP-fpm

    Install build tools we need for compilation.
    (The last command is needed if you build PHP with --with-imap, because otherwise ./configure will stop with the following error:
    checking for crypt in -lcrypt... yes
    configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.

    )

    Code:
    apt-get install build-essential
    apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-turbo-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev
    ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
    



    Prepare folders and build dir.
    Code:
    mkdir /usr/local/src/php7-build
    cd /usr/local/src/php7-build
    wget http://de1.php.net/get/php-7.0.4.tar.bz2/from/this/mirror -O php-7.0.4.tar.bz2
    tar jxf php-7.0.4.tar.bz2
    cd php-7.0.4
    


    Let's run a simple ./configure, check ./configure --help for available options if you want to customize it.
    Code:
    ./configure --prefix=/opt/php-7.0.4 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm
    


    Time to make it.
    Code:
    make
    make install
    



    Copy php.ini and php-fpm.conf to the correct locations:
    Code:
    cp /usr/local/src/php7-build/php-7.0.4/php.ini-production /opt/php-7.0.4/lib/php.ini
    cp /opt/php-7.0.4/etc/php-fpm.conf.default /opt/php-7.0.4/etc/php-fpm.conf
    cp /opt/php-7.0.4/etc/php-fpm.d/www.conf.default /opt/php-7.0.4/etc/php-fpm.d/www.conf
    


    Making sure we get a PID
    Modify /opt/php-7.0.4/etc/php-fpm.conf and uncomment

    Code:
    pid = run/php-fpm.pid
    



    We need one active php-fpm process or service won't start - leading to issues when switching PHP versions.
    Modify /opt/php-7.0.4/etc/php-fpm.d/www.conf

    Code:
    listen = 127.0.0.1:8974 ; choose an unused port
    



    Create systemd unit file: /lib/systemd/system/php-7.0.4-fpm.service
    Code:
    [Unit]
    Description=The PHP 7.0.4 FastCGI Process Manager
    After=network.target
    
    [Service]
    Type=simple
    PIDFile=/opt/php-7.0.4/var/run/php-fpm.pid
    ExecStart=/opt/php-7.0.4/sbin/php-fpm --nodaemonize --fpm-config /opt/php-7.0.4/etc/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    


    Enable .service and reload systemd
    Code:
    systemctl enable php-7.0.4-fpm.service
    systemctl daemon-reload
                


    Customize your /opt/php-7.0.4/lib/php.ini
    Code:
    ; check wether you or your customers need short open tags
    short_open_tag = On
    
    ; check wether you like the outside to know which php version you're running
    expose_php = Off
    
    ; we didn't do a debug build
    report_memleaks = Off
    
    ; UTF-8 rocks, just keep in mind that some websites still use some other charsets and you may want to
    ; overwrite this in ISPConfig website options php-section if you have issues with special charsets
    default_charset = "UTF-8"
    
    ; if you want zend opcode caching go near
    ; Dynamic Extensions ;
    ; section and add
    zend_extension=opcache.so
    
    ; choose a default timzeone for and uncomment date.timezone - right above you see a link
    ; for other timezones to choose from
    date.timezone = "Europe/Berlin"
    
    ; choose mail.log function to track mails from php mail() function, it can help to track
    ; scripts inserted on hacked sites or other abuses
    mail.log = /var/log/phpmail7.log
    
    ; It is disabled by default for maximum compatibility, but enabling it is encouraged.
    ; https://wiki.php.net/rfc/strict_sessions
    session.use_strict_mode = 1
    
    ; if you need more possible session ids, also could make session guessing a few bits harder
    ; check the comments near the configuration options within .ini file
    session.hash_function = 1
    session.hash_bits_per_character = 6
    
    ; if you enabled zend_extension=opcache.so adjust at least the following settings
    opcache.enable=1
    opcache.use_cwd=1 ; make sure it's enabled if you host more than one site using this php version
    opcache.revalidate_path=1
    ; other options as you like
    


    Test your installation. It should output something like
    PHP 7.0.4 (cli) (built: Mar 10 2016 23:08:13) ( NTS )
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

    Code:
    /opt/php-7.0.4/bin/php --version
                            


    Enable this version: Log in to your ISPConfig and go to
    System > Additional PHP Versions
    Add new PHP version
    No need to select a customer.
    Set PHP Name to something you want - suggesting: PHP 7

    # if you need PHP by CGI go to FastCGI tab

    Path to the PHP FastCGI binary: /opt/php-7.0.4/bin/php-cgi
    Path to the php.ini directory: /opt/php-7.0.4/lib

    # for PHP-FPM go to PHP-FPM tab

    # just add the filename for systemd usage without .service extension:
    Path to the PHP-FPM init script: php-7.0.4-fpm
    Path to the php.ini directory: /opt/php-7.0.4/lib
    Path to the PHP-FPM pool directory: /opt/php-7.0.4/etc/php-fpm.d


    If you need APC usercache compatibility we can add APCu
    Code:
    apt-get install autoconf
    cd /usr/local/src/php7-build
    wget http://pecl.php.net/get/apcu-5.1.3.tgz
    tar xf apcu-5.1.3.tgz
    cd apcu-5.1.3
    /opt/php-7.0.4/bin/phpize
    ./configure --with-php-config=/opt/php-7.0.4/bin/php-config
    make
    make install
                            

    Enable APCu in your /opt/php-7.0.4/lib/php.ini
    Code:
    ; near Dynamic Extensions ; section add
    extension=apcu.so
    apc.enabled=1
    apc.shm_size=32M ; if you are on a virtual server, check your /proc/user_beancounters, shared memory is often limited
    apc.ttl=7200
    apc.enable_cli=0
    
                            

    Check APCu installation
    Code:
    /opt/php-7.0.4/bin/php -i | grep apc
                            


    Start PHP 7.0.4
    Code:
    systemctl start php-7.0.4-fpm.service
    systemctl status php-7.0.4-fpm.service
    
     
    Last edited: Mar 17, 2016
    davidak, till, Guido64 and 1 other person like this.
  17. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    This is for old unsupported PHP 5.3.29 on Debian 8 using systemd.
    Note there are two additional requirements which are not needed for PHP 7, so be as careful as for the previous part.
    And again, I added APC ( with opcode caching, hence the missing u after APC ).

    Switched back and forth betwen default,7,5.3 in random order, worked like a charm

    Install build tools we need for compilation.

    Code:
    apt-get install build-essential
    apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-turbo-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libkrb5-dev libpq-dev libxml2-dev libxslt1-dev
    ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a
    apt-get install libxpm-dev libmysqlclient-dev
    



    Prepare folders and build dir.
    Code:
    # we need this or we can't find freetype.h easily :(
    mkdir /usr/include/freetype2/freetype
    ln -s /usr/include/freetype2/freetype.h /usr/include/freetype2/freetype/freetype.h
    
    
    mkdir /usr/local/src/php53-build
    cd /usr/local/src/php53-build
    wget http://de1.php.net/get/php-5.3.29.tar.bz2/from/this/mirror -O php-5.3.29.tar.bz2
    tar jxf php-5.3.29.tar.bz2
    cd php-5.3.29
    


    Let's run a simple ./configure, check ./configure --help for available options if you want to customize it.
    Code:
    ./configure --prefix=/opt/php-5.3.29 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-fpm  --with-xpm-dir=/usr
    


    Time to make it.
    Code:
    make
    make install
    mkdir /opt/php-5.3.29/etc/pool.d
    



    Copy php.ini and php-fpm.conf to the correct locations:
    Code:
    cp /usr/local/src/php53-build/php-5.3.29/php.ini-production /opt/php-5.3.29/lib/php.ini
    cp /usr/local/src/php53-build/php-5.3.29/sapi/fpm/php-fpm.conf /opt/php-5.3.29/etc/php-fpm.conf
    


    Making sure we get a PID
    Modify /opt/php-5.3.29/etc/php-fpm.conf and uncomment

    Code:
    pid = run/php-fpm.pid
    



    We need one active php-fpm process or service won't start - leading to issues when switching PHP versions.
    Also we need PHP to tell from where to include additional conf files
    Modify /opt/php-5.3.29/etc/php-fpm.conf

    Code:
    listen = 127.0.0.1:8953 ; choose an unused port
    include=/opt/php-5.3.29/etc/pool.d/*.conf
    



    Create /lib/systemd/system/php-5.3.29-fpm.service
    Code:
    [Unit]
    Description=The PHP 5.3.29 FastCGI Process Manager
    After=syslog.target network.target
    
    [Service]
    Type=simple
    PIDFile=/opt/php-5.3.29/var/run/php-fpm.pid
    ExecStart=/opt/php-5.3.29/sbin/php-fpm --nodaemonize --fpm-config /opt/php-5.3.29/etc/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    


    Enable .service and reload systemd
    Code:
    systemctl enable php-5.3.29-fpm.service
    systemctl daemon-reload
                


    Customize your /opt/php-5.3.29/lib/php.ini
    Code:
    ; check wether you or your customers need short open tags
    short_open_tag = On
    
    ; check wether you like the outside to know which php version you're running
    expose_php = Off
    
    ; we didn't do a debug build
    report_memleaks = Off
    
    ; UTF-8 rocks, just keep in mind that some websites still use some other charsets and you may want to
    ; overwrite this in ISPConfig website options php-section if you have issues with special charsets
    default_charset = "UTF-8"
    
    ; choose a default timzeone for and uncomment date.timezone - right above you see a link
    ; for other timezones to choose from
    date.timezone = "Europe/Berlin"
    
    ; choose mail.log function to track mails from php mail() function, it can help to track
    ; scripts inserted on hacked sites or other abuses
    mail.log = /var/log/phpmail53.log
    
    ; if you need more possible session ids, also could make session guessing a few bits harder
    ; check the comments near the configuration options within .ini file
    session.hash_function = 1
    session.hash_bits_per_character = 6
    
    ; other options as you like
    


    Test your installation. It should output something like
    PHP 5.3.29 (cli) (built: Mar 11 2016 01:02:53)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies

    Code:
    /opt/php-5.3.29/bin/php --version
                            


    Enable this version: Log in to your ISPConfig and go to
    System > Additional PHP Versions
    Add new PHP version
    No need to select a customer.
    Set PHP Name to something you want - suggesting: PHP 5.3

    # if you need PHP by CGI you have to compile again without --enable-fpm but with --enable-cgi
    # so no FastCGI option this time

    # for PHP-FPM go to PHP-FPM tab

    # just add the filename for systemd usage without .service extension:
    Path to the PHP-FPM init script: php-5.3.29-fpm
    Path to the php.ini directory: /opt/php-5.3.29/lib
    Path to the PHP-FPM pool directory: /opt/php-5.3.29/etc/pool.d




    If you need APC opcode and usercache we can add APC
    Code:
    apt-get install autoconf
    cd /usr/local/src/php53-build
    wget https://pecl.php.net/get/APC-3.1.13.tgz
    tar xf APC-3.1.13.tgz
    cd APC-3.1.13
    /opt/php-5.3.29/bin/phpize
    ./configure --with-php-config=/opt/php-5.3.29/bin/php-config
    make
    make install
                            

    Enable APC in your /opt/php-5.3.29/lib/php.ini
    Code:
    ; near Dynamic Extensions ; section add
    extension=apc.so
    apc.enabled=1
    apc.shm_size=32M ; if you are on a virtual server, check your /proc/user_beancounters, shared memory is often limited
    apc.ttl=7200
    apc.enable_cli=0
    apc.cache_by_default=1
    
                            

    Check APC installation
    Code:
    /opt/php-5.3.29/bin/php -i | grep apc
                            


    Start PHP 5.3.29
    Code:
    systemctl start php-5.3.29-fpm.service
    systemctl status php-5.3.29-fpm.service
    
     
    Last edited: Mar 11, 2016
    davidak, till and Guido64 like this.
  18. Guido64

    Guido64 Member

    Unreal man you are lightning fast. I didn't expect you posted it this fast. Sunday night or Monday I'm going to install 5.3.29 and let you know how it went.

    I am sure lots of others will be thankful as i am you wrote this comprehensive tutorial how to install the old php 5.3.29 version on debian 8.

    Thank you a million!
     
  19. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    nah, I used the linked tutorials ( e.g. official howtos from howtoforge ) above as a base... just made few adjustments for the 5.3.29 version :)
    Hope it'll work for you, too - I didn't test rebooting the server yet, but I don't see why this shouldn't work :)

    You also might want to add https://suhosin.org/stories/install.html

    To ensure only .php extensions are parsed ( for example bug in configuration for nginx or extended security ) you might want to change

    /usr/local/ispconfig/server/conf/php_fpm_pool.conf.master
    Code:
    security.limit_extensions = .php
    This is expecting a whitespace seperated list if you need to allow multiple extensions.
    Add this somewhere at the end or outside any <...if...> statements
     
    Last edited: Mar 11, 2016
    Guido64 likes this.
  20. Guido64

    Guido64 Member

    Halfway the 5.3.29 tutorial there is a empty code thingy is this a mistake or a missing configuration?
    Sadly i'm going away for few days tomorrow afternoon but i will definitely let you know how it went wen i installed php 5.3.29 wen i am back.

    I am also happy with the extra explanations you wrote in the tutorial I understand a little better how it works.

    Great weekend!
     
    ztk.me likes this.

Share This Page