Setting a PHP version per domain/directory on a shared server

You can set a custom PHP version per domain or directory by creating a .htaccess file containing the following text or by placing it at the top of an existing .htaccess file (choose the appropriate version):

# PHP 5.3 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp53

</FilesMatch>

 

# PHP 5.4 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp54

 

</FilesMatch>

 

# PHP 5.5 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp55

 

 

</FilesMatch>

 

# PHP 5.6 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp56

 

 

</FilesMatch>

 

# PHP 7.0 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp70

 

 

</FilesMatch>

 

# PHP 7.1 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp71

 

 

</FilesMatch>

 

# PHP 7.2 

 

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">

SetHandler application/x-lsphp72

 

 

</FilesMatch>

 

As with any .htaccess file it works recursively so will affect all directories below the one it's in, if you need anything below to use a different version you can place another .htaccess file with the appropriate version in it.

  • php, version
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How can I change or upgrade my PHP version

On a shared server the PHP version  can be changed easily via the "Select PHP Version" tool, once...

Changing PHP variables on a shared server

Common PHP variables and the PHP version running on a cPanel account can be changed via the...