• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Two PHP versions linux Plesk HOWTO

Igor Smitran

New Pleskian
Few days ago i was exchanging emails with Parallels support. I was asking them to help me to setup two php versions on linux plesk server. After few emails they answeared me that it is not possible. It didn't help when i told them that i was using fastcgi on my own hosting server and that i was having 3 php versions configurable per customer. Nop... Their answear was
As of now there is no option available in the linux, where you can choose php as per the customers.
Hope you are clear now. If you have any further help, feel free to get back to us. We would be glad to assist you further.
And, there i was, left helpless, without possibility to finish migration from my old hosting server to our new and shiny Plesk. I needed newer php version because php provided by my linux distro is 5.1.
So, i logged in to Plesk server and spend around 20 minutes planning how to intercept Plesk calls. And it is done.
For this to work you have to have php running as fastcgi (it is most secure way, so i assume that everyone is running php as fastcgi)
Here it goes:

1. ssh to your plesk server, download php source, unpack it and configure it
Code:
ssh yourserver -l root
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

NOTICE: you HAVE TO USE PREFIX switch in order to have your new php installed inside one directory, for example:

Code:
./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' '--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'
As you can see, my prefix was /usr/local/php540-cgi/
Choosing a prefix is a MUST because that way your new php installation will not interfere with older php used by plesk.

2. compile your php
Code:
make

3. install your new php
Code:
make install

4. create php wrapper
for example, let's say that you have a customer blabla.com that uses some newer php functions that don't exist in php 5.1. Let's call that customer blabla.com. For him we will tell apache to use our new php (5.4.0)
Code:
cd /var/www/vhosts/blabla.com/cgi-bin
mkdir .cgi_wrapper
cd .cgi_wrapper

now we will create new file and name it .phpwrapper
Code:
vi .phpwrapper

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

let's strengthen our new files and dirs permissions and privileges:
Code:
cd /var/www/vhosts/blabla.com/cgi-bin
chmod 101 .cgi_wrapper
chmod 500 .cgi_wrapper/.phpwrapper
chown blabla.com:psacln .cgi_wrapper -R
chattr -R +i .cgiwrapper
 
5. make apache aware of our wrapper
plesk offers a functionality of changing httpd setup per host. we will use that functionality to tell apache that for blabla.com it needs to use our new wrapper, instead of one provided by plesk:
Code:
cd /var/www/vhosts/blabla.com/conf

we will create file named vhost.conf
Code:
vi vhost.conf

file content:
Code:
<Directory /var/www/vhosts/blabla.com/httpdocs>
RemoveHandler fcgid-script
<IfModule mod_fcgid.c>
    AddHandler fcgid-script .php
    <Files ~ (\.php)>
        SetHandler fcgid-script
        FCGIWrapper /var/www/vhosts/blabla.com/cgi-bin/.cgi_wrapper/.phpwrapper .php
        Options +ExecCGI
        allow from all
    </Files>
</IfModule>
</Directory>
So, we have told apache not to use plesk php wrapper (RemoveHandler fcgid-script) and instead of that we have created a new handler for php files. When executing php files on blabla.com domain apache will call our wrapper and use new php that we installed

6. we need to reconfigure blabla.com domain
Code:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain blabla.com

7. and restart apache
Code:
/etc/init.d/httpd restart

That's it. For every domain that needs some extra functions provided only in php versions newer than one provided with your plesk distro you can do steps 4,5,6 and 7 (replace blabla.com with your customer domain name) and that's all.
 
Igor Smitran, Thank you. Your concern is clear, we will consider making corresponding KB article.
 
You should also consider implementing this into plesk. Let's leave it to the administrator installing of php, in that case you should consider:

1. possibility of inserting php version awareness into plesk (something windows version already has)
2. automating creation of wrapper and httpd.conf
 
re

I'm replying to this topic to subscribe to it.

Also I think it would be good to have plesk unlimited options,
like I saw in one of DirectAdmin instalations - screenshot: http://d.pr/i/eWQr

So we have PHP 5.2, 5.3, 5.4 and 5.5 soon.

It will make Plesk more powerfull than ever, since PHP version problem is from the very beginning and always was.
 
That would be great feature. Now if you have lot clients with different PHP versions you need separate servers to fit your needs. With this feature all clients can fitted in one server.
 
Thank you for this great Guide!

We would also like to see this feature implemented into Plesk - would be a great addition!!

Andreas Schnederle-Wagner
 
Last edited:
The problem is that at least one of the versions of PHP would have to be provided by Parallels, and updated by them too.

Maybe it would be best just to have an "additional php" selection within the hosting selection in Plesk (similar to the alternative webmail option) and let the admin worry about obtaining, compiling and installing? I'd really like that.
 
For me as Server-Admin it would be perfectly OK to manage the different PHP Versions on Plesk Servers. Would just be a killer Feature if our Plesk Admins could choose between them in GUI ... so they don't need a Server-Admin anytime they need a different PHP Version for a Hosting ... :)
 
btw) you got a typo in the KB

# 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 .cgiwrapper

last Line should be:
chattr -R +i .cgi_wrapper

And I would suggest adding this param to the PHP configure - otherwise all PHP installations will share the same "additional config files":
'--with-config-file-scan-dir=/usr/local/php540-cgi/php.d'
 
Thank you. I have updated article with your recommendations.
 
btw) you got a typo in the KB



last Line should be:


And I would suggest adding this param to the PHP configure - otherwise all PHP installations will share the same "additional config files":

If you are talking about php.ini then you are wrong, php.ini location is inside PHPRC environment variable. Since every domain has different wrapper, php.ini location is here:

Code:
export PHPRC=/var/www/vhosts/blabla.com/etc/

so, php.ini is inside user directory and you are able to setup php.ini per user, easily.

Thank you for typo notice :)
 
Last edited:
Hi,

speaking about "/etc/php.d/xxx" <-- those will be shared along all PHP installs without passing '--with-config-file-scan-dir=/usr/local/php540-cgi/php.d' to configure - happened when I installed second PHP Version on our Plesk Server ;-)

Andreas
 
I have Plesk 11 installed on CentOS 6 with PHP 5.3.3 and wanted to install PHP 5.2.17 for some websites using your instructions.
But after that I`ve got an error in /var/www/vhosts/domain.com/statistics/logs/error_log saying:
[warn] [client x.x.x.x] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[error] [client x.x.x.x] Premature end of script headers: index.php

Do you know what could be wrong?
 
Well, I have installed php in /usr/local/php520-cgi/

And trying ./php -v I get:
PHP 5.2.17 (cli) (built: Sep 25 2012 11:02:20)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

with ./php -i I get lots of information.

By default command php -v I get:
PHP 5.3.3 (cli) (built: Jul 3 2012 16:53:21)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with the ionCube PHP Loader v4.0.14, Copyright (c) 2002-2011, by ionCube Ltd.
 
I did this commands:

# cd /var/www/vhosts/domain.com/cgi-bin
# chmod 101 .cgi_wrapper
# chmod 500 .cgi_wrapper/.phpwrapper
# chown client_code .cgi_wrapper -R
# chgrp 505 .cgi_wrapper -R
# chattr -R +i .cgi_wrapper

So the chown/chmod is made by this.
 
Back
Top