How to Install two php version on plesk

Install-two-php-version-on-plesk

How to Install two php version on plesk

1. SSH to your Parallels Plesk Panel (PP) server as root, download the PHP source, unpack it, and configure it


# cd /usr/local/src
# mkdir php540
# cd php540
# wget http://www.php.net/get/php-5.4.0.tar.gz/from/at2.php.net/mirror
# tar xzvf php-5.4.0.tar.gz
# cd php-5.4.0

Note: You HAVE TO USE THE PREFIX SWITCH in order 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-fastcgi' '--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 a MUST because it prevents your new PHP installation from interfering with the older PHP version used by PP.

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 some newer PHP functions that don’t exist in the default PHP 5.1. Let’s call that customer domain.com. We will tell Apache to use our new PHP version (5.4.0) for him:
# 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 necessary permissions and privileges for created files and directories:
# 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. PP offers an option to change the httpd setup per host. We will use this option to tell Apache domain.com needs to use our new PHP wrapper instead of the one provided by PP:
# cd /var/www/vhosts/domain.com/conf

Create a vhost.conf file there with the following content:


RemoveHandler fcgid-script

AddHandler fcgid-script .php

SetHandler fcgid-script
FCGIWrapper /var/www/vhosts/domain.com/cgi-bin/.cgi_wrapper/.phpwrapper .php
Options +ExecCGI
allow from all

 

So far, we have told Apache not to use the default PP 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 new PHP 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

————————–
Regards,
Arun Pingale
Level-3 Systems Administrator
http://24×7servermanagement.com/
Email: Arun@24×7servermanagement.net

Share this post


*/