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:

date.timezone=Europe/Paris
extension=mysql.so
extension=json.so
extension=nd_mysqli.so
extension=intl.so
extension=mcrypt.so
extension=gd.so
extension=xml.so
extension=xmlreader.so
extension=xmlrpc.so
extension=xmlwriter.so
extension=soap.so
extension=tidy.so
extension=bcmath.so
extension=dom.so
extension=fileinfo.so
extension=imap.so
extension=zip.so
extension=mcrypt.so
extension=memcache.so
extension=memcached.so
extension=intl.so
extension=pdo.so
extension=fileinfo.so
extension=mbstring.so
extension=ioncube.so
extension=imagick.so
extension=pdo_mysql.so
extension=mysqli.so

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

memory_limit=256M
max_execution_time=120
date.timezone=Europe/Paris
extension=mysql.so
extension=json.so
extension=nd_mysqli.so
extension=intl.so
extension=mcrypt.so
extension=gd.so
extension=xml.so
extension=xmlreader.so
extension=xmlrpc.so
extension=xmlwriter.so
extension=soap.so
extension=tidy.so
extension=bcmath.so
extension=dom.so
extension=fileinfo.so
extension=imap.so
extension=zip.so
extension=mcrypt.so
extension=memcache.so
extension=memcached.so
extension=intl.so
extension=pdo.so
extension=fileinfo.so
extension=mbstring.so
extension=ioncube.so
extension=imagick.so
extension=pdo_mysql.so
extension=mysqli.so
extension=opcache.so

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
</FilesMatch>
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
</FilesMatch>
AddHandler application/x-httpd-php73 .php
suPHP_ConfigPath /home/your_login/php.ini

Conclusion

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.

Comments