In some hosting environments, multiple PHP versions may be installed simultaneously, and a different PHP version can be assigned to each directory. It is possible to make this version selection with the .htaccess file, and one of the most common methods is the AddHandler directive. In this article, we will detail the method of assigning PHP 7.4 version using application/x-httpd-php74.
Code Explanation
AddHandler application/x-httpd-php74 .php
What does this line do?
-
Ensures that all files with the
.phpextension are interpreted by Apache with thePHP 7.4engine. -
The
application/x-httpd-php74expression is the definition given to the PHP 7.4 version by the hosting provider.
Supporting Alternative:
<IfModule mod_php7.c>
AddHandler application/x-httpd-php74 .php
</IfModule>
-
These rules are applied if the
mod_php7.cmodule is installed. -
This block is ignored if mod_php is not used in the Apache installation.
Usage Purposes
-
When different PHP versions are needed for different projects on the same hosting account.
-
If PHP 8.x is installed but an old framework like Laravel 6, 7 only works with PHP 7.4.
-
For developers who manage the environment with a limited hosting panel to gain flexibility.
Things to Consider
-
These directives only work on shared hosting or environments that support mod_php.
-
The hosting provider must be naming the PHP 7.4 version
application/x-httpd-php74. Some platforms may have different definitions (such as php74, php7.4, x-httpd-php74). -
This command may be ineffective if FPM or FastCGI is used instead of
mod_phpon Apache. In this case, version selection is required from the panel.
By adding the line AddHandler application/x-httpd-php74 .php to the .htaccess file, it becomes possible to provide directory-based PHP version control. This method offers a very useful solution, especially in projects that require old PHP compatibility. However, it should be ensured that it is suitable for the technical infrastructure of the environment in which it is used.