How do I parse HTML files as PHP?

Updated by Josselyn Rodriguez

You can use the following directive in .htaccess to parse HTML files as PHP. The exact line that you need to add will be different for different servers, depending on exactly how Apache and PHP are installed and configured. But one of these lines (or sets of lines) should do the trick:

AddHandler x-httpd-php .html .htm 
AddHandler php-script .php .html .htm
# If the server is using PHP 5 use:
# AddHandler php5-script .php .html .htm

On cPanel Servers :

<FilesMatch "\.(php4|php5|php3|php2|php|phtml|htm|html)$">
AddType application/x-httpd-ea-php72 .php .htm .html
AddHandler application/x-httpd-ea-php72 .php .htm .html
</FilesMatch>

** Depending on the PHP version you are using, you will need to replace php72 with the version you are using. For example, if you are using PHP 7.0, use application/x-httpd-ea-php70.

On CloudLinux Servers (All our Linux shared servers use CloudLinux) :

<FilesMatch "\.(php4|php5|php3|php2|php|phtml|htm|html)$">
AddType application/x-httpd-alt-php72 .php .htm .html
AddHandler application/x-httpd-ea-php72 .php .htm .html
</FilesMatch>

** Depending on the PHP version you are using, you will need to replace php72 with the version you are using. For example, if you are using PHP 7.0, use application/x-httpd-alt-php70.

To verify that it works, make a file called phptest.html and put some PHP code into it. Here is some code you can use for testing:

<?PHP
echo "PHP is working.";
?>

Upload phptest.html tothe server and access it via the browser. If the page displays "PHP is working", then you're all done; but if it displays the PHP code or nothing at all, then it didn't work and you'll need to try different lines in your .htaccess file.

Having trouble? Contact us and our team will be happy to help.


How did we do?