How to customize the PHP version per directory at o2switch

Force the PHP version you want into a directory at o2switch

Currently, I use the o2switch host for my PrestaShop or other CMS version tests.

This host allows you to use several separate environments with its MOON option, but in my case, I need to be able to customize the PHP version used by subdirectories since I have one directory per version of PrestaShop and you all know, the PHP versions supported by PrestaShop are quite flexible.

To successfully do this, first, refer to the very good documentation offered by o2switch.

So I'm going to take a part of it to explain you simply how I set it up on my server.

Creation of the php.ini file

This part is quite simple, you just have to create a php.ini file on your web server.

This file can be saved in any directory of your server since we will define the precise server address when we want to use it.

For example, on your o2switch hosting, you can save it at the root of the hosting, before entering the public_html directory, so that it is outside the web area that can be displayed and therefore it allows to secure the content.

This will give you something like: /home/your_login/php.ini

In this file you will configure the extensions and the elements you want to activate.

Like the example provided by o2switch:


Personally, I have slightly modified its content, which shows you what can be done with it:


Let's force the PHP version for any directory

Once your php.ini file is in place on your server, you only need to adapt the .htaccess file of a directory so that it uses a specific version of PHP and that this configuration is applied to all subdirectories unless a new configuration defined in another .htaccess file changes this choice.

The list of PHP versions available on your host is of course constantly changing and I advise you to refer to the list in the cPanel menu: Select a PHP version

Choose PHP 5.6

Let's open, in our case for PrestaShop or thirty bees, the .htaccess file already present at the root of the installation directory of our store.

At the top of the file, before the line

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

Put the following information:

#PHP 5.6 :
<FilesMatch \.php$>
SetHandler application/x-httpd-php56
AddHandler application/x-httpd-php56 .php
suPHP_ConfigPath /home/your_login/php.ini

Of course, customize the line suPHP_ConfigPath /home/your_login/php.ini with the server address of your previously created php.ini file.

Choose PHP 7.3

You will use the same php.ini file or you can create a new one in another directory by remembering to change its server address when setting up the .htaccess file.

So you just have to do the same thing as for the PHP 5.6 version above, but calling the 7.3 version like this:

#PHP 7.3 :
<FilesMatch \.php$>
SetHandler application/x-httpd-php73
AddHandler application/x-httpd-php73 .php
suPHP_ConfigPath /home/your_login/php.ini


You have understood the principle, I will not list all the possibilities of versions available at o2switch to date.

I hope this tip will be useful for your developments, like updating your PrestaShop versions on a single server using multiple versions of PHP.