A few days ago one of our techs was facing a strange issue while trying to execute PHP in HTML on EasyApache 4 from cPanel. After upgrading to EA4, a previously working .htaccess hack that was used to execute PHP in HTML was no longer working. This was the rule we used for our customer:
AddHandler application/x-httpd-php5 .html
Tried several things, even a simple test.html file with this content inside, and it was not executed ok:
<html> <head></head> <body> Hello, today is <?php echo date('l, F jS, Y'); ?>. </body> </html>
While using EasyApache 3 it was working, but not on EA4. EA4 was built with latest version of Apache 2.4 with PHP 5.5, 5.6, 7.0 and 7.1. The file was not prompting to download the file, it was just not executing any php code at all and was displaying only the HTML code.
How can I Execute PHP in HTML on EasyApache 4?
EasyApache 4 introduced many important changes in the way cPanel handles Apache and PHP modules managemnet. One of them is the way EA4 manages PHP, right now thanks to the introduction of MultiPHP, the old hack to execute PHP in HTML no longer works because the PHP interpreter is different.
The way to execute PHP in HTML on EasyApache 4 is using the new PHP handlers that are coming with MultiPHP from cPanel. In this case, the site was using PHP 5.6, and this was the code that did work on the .htaccess file:
AddHandler application/x-httpd-ea-php55 .html
That’s all, this way you can execute PHP in HTML on EasyApache 4 with the new PHP handlers from latest cPanel versions.