On shared hosting servers, multiple versions of PHP can be simultaneously installed and various applications have to run with different PHP versions. How can we set up, for example, the app A running with PHP 7 while the app B running with PHP 8? This post will instruct you how to do it.
Table of Contents
Introduction
I am running two applications running on the same web hosting server: this technical blog site and my diary. The former is based on WordPress and kept up-to-dated to PHP 8 while the latter is built with CodeIgniter 3.x which is compatible up to PHP 7. Remember that changing PHP version per directory is an advanced option.
How to do?
The steps are described below. Remember to check which web server is running on your hosting.
- Open the
.htaccess
file in the root directory of the website to set a different PHP version to run on. - Copy and paste one of the code blocks below to the
.htaccess
file. - Save and exit your editor.
Set PHP version using .htaccess
on Apache servers
PHP 8.4 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php84” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php84___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 8.3 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php83” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php83___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 8.2 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php82” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php82___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 8.1 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php81” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php81___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 8.0 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php80” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php80___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 7.4 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php74” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php74___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 7.3 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php73” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php73___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 7.2 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php72” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php72___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 7.1 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php71” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php71___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
PHP 7.0 .htaccess code
# php -- BEGIN cPanel-generated handler, do not edit # Set the “alt-php70” package as the default “PHP” programming language. <ifmodule mime_module> AddHandler application/x-httpd-alt-php70___lsphp .php .php5 .phtml </ifmodule> # php -- END cPanel-generated handler, do not edit |
Set PHP version using .htaccess on LiteSpeed servers
PHP 8.4
AddHandler application/x-httpd-alt-php84 .php .php8 .phtml |
PHP 8.3
AddHandler application/x-httpd-alt-php83 .php .php8 .phtml |
PHP 8.2
AddHandler application/x-httpd-alt-php82 .php .php8 .phtml |
PHP 8.1
AddHandler application/x-httpd-alt-php81 .php .php8 .phtml |
PHP 8.0
AddHandler application/x-httpd-alt-php80 .php .php8 .phtml |
PHP 7.4
AddHandler application/x-httpd-alt-php74 .php .php7 .phtml |
Key differences between Apache and LiteSpeed server
The main differences between Apache and LiteSpeed web servers center on their architecture, performance, licensing, and resource usage.1 LiteSpeed is generally superior in speed and efficiency, while Apache is dominant in market share, compatibility, and is free to use.2
Here’s a breakdown of the key differences:
Feature | Apache HTTP Server | LiteSpeed Web Server (LSWS) |
Architecture | Process-based/Thread-based model (spawns a new process or thread for each connection), which can consume more resources under heavy load. | Event-driven architecture (similar to Nginx), which handles all connections in a single process, making it highly efficient. |
Performance | Moderate. Can be slower and less efficient, especially with high concurrent connections, and requires extra modules for caching. | High. Significantly faster, particularly with static content, and better at handling high traffic with low resource consumption. |
Resource Usage | Higher memory and CPU usage, particularly with numerous concurrent users. | Lower memory and CPU usage due to its efficient architecture. |
Licensing/Cost | Free and Open-Source. | Proprietary (commercial) with licensing fees for the Enterprise version. A free, open-source version, OpenLiteSpeed (OLS), is also available. |
Caching | Requires external modules (like mod_cache ) for effective caching, which need careful configuration. |
Built-in caching engine (LiteSpeed Cache or LSCache) with advanced features and associated CMS plugins (e.g., WordPress). |
Compatibility | Excellent and supports nearly all operating systems (Linux, Windows, Unix-like). | Designed as a drop-in replacement for Apache, meaning it can read Apache’s config files and use .htaccess . Primarily focused on Linux. |
Support | Relies on extensive community support and documentation since it is open-source. | Provides dedicated technical support for the paid Enterprise version. |
References
[1] Running Different PHP Versions with Apache on Ubuntu, accessed on 28th September, 2025
[2] How to set PHP version per directory, accessed on 28th September, 2025
[3] Experience the LiteSpeed Difference, accessed on 28th September, 2025