[Plesk 11 only] How to Install and Use two versions of PHP on the same Plesk 11.0 for Linux Server

Refers to:

  • Plesk 11.0 for Linux

Created:

2016-11-16 13:22:02 UTC

Modified:

2017-01-31 22:30:20 UTC

2

Was this article helpful?


Have more questions?

Submit a request

[Plesk 11 only] How to Install and Use two versions of PHP on the same Plesk 11.0 for Linux Server

Fixed Since

Plesk for Linux has supported running multiple versions of PHP on the server since version 11.5 (see the release notes ). Instructions on installing and configuring PHP on Plesk 11.5 servers are available in the Plesk Administrator's Guide .

Note: For Plesk 11.5, 12.0 use this article: #213909265 How to enable multiple PHP versions in Plesk for Linux

Resolution

NOTE: The instructions below are for Plesk 11.0.9 only. For Plesk 11.5, use the documentation mentioned above.

For the following to work, you must have PHP running as fastcgi.

  1. SSH to your Plesk server as root, download the PHP source, unpack it, and configure it:

    # cd /usr/local/src
    # mkdir php540
    # cd php540
    # wget http://museum.php.net/php5/php-5.4.0.tar.gz
    # tar xzvf php-5.4.0.tar.gz
    # cd php-5.4.0

    Note: You MUST use the prefix switch for your new PHP to be installed inside a single directory. For example:

    # ./configure '--with-libdir=lib64' '--cache-file=../config.cache' '--prefix=/usr/local/php540-cgi' '--with-config-file-path=/usr/local/php540-cgi/etc' '--disable-debug' '--with-pic' '--disable-rpath' '--enable-cgi' '--with-bz2' '--with-curl' '--with-freetype-dir=/usr/local/php540-cgi' '--with-png-dir=/usr/local/php540-cgi' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr/local/php540-cgi' '--with-openssl' '--with-pspell' '--with-pcre-regex' '--with-zlib' '--enable-exif' '--enable-ftp' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-wddx' '--with-kerberos' '--with-unixODBC=/usr' '--enable-shmop' '--enable-calendar' '--without-sqlite3' '--with-libxml-dir=/usr/local/php540-cgi' '--enable-pcntl' '--with-imap' '--with-imap-ssl' '--enable-mbstring' '--enable-mbregex' '--with-gd' '--enable-bcmath' '--with-xmlrpc' '--with-ldap' '--with-ldap-sasl' '--with-mysql=/usr' '--with-mysqli' '--with-snmp' '--enable-soap' '--with-xsl' '--enable-xmlreader' '--enable-xmlwriter' '--enable-pdo' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pear=/usr/local/php540-cgi/pear' '--with-mcrypt' '--enable-intl' '--without-pdo-sqlite' '--with-config-file-scan-dir=/usr/local/php540-cgi/php.d'

    As you can see, this is the prefix: /usr/local/php540-cgi/

    Choosing a prefix is ESSENTIAL because it prevents your new PHP installation from interfering with the older PHP version used by Plesk.

  2. Compile your PHP:

    # make
  3. Install your new PHP:

    # make install
  4. Create a PHP wrapper. For example, let's say you have a customer, domain.com , that uses newer PHP functions that do not exist in the default PHP 5.1. We will tell Apache to use our new PHP version (5.4.0):

    # cd /var/www/vhosts/domain.com/cgi-bin
    # mkdir .cgi_wrapper
    # cd .cgi_wrapper

    Create a new file, .phpwrapper , with the following content:

    #!/bin/sh
    export PHPRC=/var/www/vhosts/domain.com/etc/
    export PHP_FCGI_CHILDREN=4
    export PHP_FCGI_MAX_REQUESTS=1000
    exec /usr/local/php540-cgi/bin/php-cgi

    Set the necessary permissions and privileges for the files and directories you created:

    # chgrp psaserv /var/www/vhosts/domain.com/cgi-bin
    # cd /var/www/vhosts/domain.com/cgi-bin
    # chmod 101 .cgi_wrapper
    # chmod 500 .cgi_wrapper/.phpwrapper
    # chown domain.com:psacln .cgi_wrapper -R
    # chattr -R +i .cgi_wrapper
  5. Make Apache aware of our new PHP wrapper. Plesk offers an option to change the httpd setup per vhost (it could be either a domain or subdomain). We will use this option to tell Apache that, as per our example, domain.com needs to use our new PHP wrapper instead of the one provided by Plesk:

    # cd /var/www/vhosts/domain.com/conf

    Create a vhost.conf file with the following content:

    <Directory /var/www/vhosts/domain.com/httpdocs>
    RemoveHandler fcgid-script
    <IfModule mod_fcgid.c>
    AddHandler fcgid-script .php
    <Files ~ (\\.php)>
    SetHandler fcgid-script
    FCGIWrapper /var/www/vhosts/domain.com/cgi-bin/.cgi_wrapper/.phpwrapper .php
    Options +ExecCGI
    allow from all
    </Files>
    </IfModule>
    </Directory>

    So far, we have told Apache not to use the default Plesk PHP wrapper (RemoveHandler fcgid-script) and instead, we created a new handler for PHP files. When executing PHP files on the "domain.com" domain, Apache will call the new PHP wrapper and use the version that was installed in Steps 1-3.

  6. Reconfigure the "domain.com" domain:

    # /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
  7. Restart Apache:

    # /etc/init.d/httpd restart

    For every domain that needs extra functions that are only available in newer PHP versions, perform Steps 4, 5, 6, and 7 (replacing "domain.com" with your customer's domain name).

Have more questions? Submit a request
Please sign in to leave a comment.