Changing PHP Version on Plesk

Recently, I had to setup a server which uses Plesk, and PHP 5.4 to also run PHP 5.3 side-by-side for a certain domain. Ramblings of my efforts are below.

Server currently runs on 5.4.33, however we have configured an additional version of PHP 5.3 for a site which requires a PHP 5.3 Depreciated Function. This is installed in /usr/local/php53-cgi/. We can switch Domains over to this version manually if requires as follows. The guide below uses as the domain.

First we create a PHP wrapper.

cd /var/www/vhosts/
mkdir .cgi_wrapper
cd .cgi_wrapper
touch .phpwrapper

Edit the .phpwrapper file just created, and populate it with the following:

export PHPRC=/var/www/vhosts/
exec /usr/local/php53-cgi/bin/php-cgi

Set the necessary permissions and privileges for the created files and directories (Run ls -l /var/www/vhosts/ to find the domains username - listed in the below example as example):

chgrp psaserv /var/www/vhosts/
cd /var/www/vhosts/
chmod 101 .cgi_wrapper
chmod 500 .cgi_wrapper/.phpwrapper
chown example:psacln .cgi_wrapper -R
chattr -R +i .cgi_wrapper

Make Apache aware of our new PHP wrapper. Plesk offers an option to change the httpd setup per vhost (it could be either domain or subdomain). We will use this option to tell Apache that, as per our example, needs to use our new PHP wrapper instead of the one provided by Plesk:

cd /var/www/vhosts/

Create a vhost.conf file with the following content:

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

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, Apache will call the new PHP wrapper and use the version that was installed.

Reconfigure the “” domain:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain

Test that the Apache Configuration is ok, then Restart Apache:

service httpd configtest
service httpd restart