Knowledge Base
How to Execute PHP Code in HTML Files on cPanel or Plesk
When you want PHP scripts to run inside .html files. This article explains how to enable PHP execution in HTML files on cPanel or Plesk.
We might have encountered this situation at least once where we are trying to run a .html using PHP. All the PHP handler based typecasting we tried ends up with the Page getting downloaded.
Here is a solution for the same if the issue is happening in our shared (SDH/MDH/RH) hosting environment. Whenever you try to change the PHP version for any domain via Multi-PHP manager, it will add the handler code in the .htaccess as follows:
You just have to edit it and change it as follows:
The above-mentioned line in .htaccess allows you to run the PHP code embedded inside .htm or .html files using the PHP version currently set via Multi-PHP manager and vice versa.
If you want to add any other file extensions, you can add them at the end of the line.
Sample code for testing:
Embedding PHP in HTML : info.html
Embedding HTML in PHP:
info.php:
Here is a solution for the same if the issue is happening in our shared (SDH/MDH/RH) hosting environment. Whenever you try to change the PHP version for any domain via Multi-PHP manager, it will add the handler code in the .htaccess as follows:
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
You just have to edit it and change it as follows:
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml .htm .htmlThe handler will change based on the PHP version you choose for the domain via the Multi-PHP manager.
The above-mentioned line in .htaccess allows you to run the PHP code embedded inside .htm or .html files using the PHP version currently set via Multi-PHP manager and vice versa.
If you want to add any other file extensions, you can add them at the end of the line.
Sample code for testing:
Embedding PHP in HTML : info.html
<html> <title>PHP Info Page </title> <body> <? phpinfo(); ?> </body> </html>
Embedding HTML in PHP:
info.php:
<? include 'helloworld.html'; phpinfo(); ?>