Overview
To run PHP code inside a file with an .html extension on DreamHost, you add an AddHandler/FcgidWrapper directive to your .htaccess file so the .html file is processed as PHP. This article explains how, using an .htaccess file.
Background
Normally, when PHP and HTML are combined in the same file, the file uses a .php extension to display the content in the browser. For example, the following file is named hello.php:
<html
<body>
<?php
echo "hello";
?>
</body>
</html>However, if you need to place PHP code in a file with an .html extension, you must first add a handler to your .htaccess file so the PHP code is able to function.
How do I use an .htaccess file to run PHP in an HTML file?
You must use an .htaccess file to run PHP code. If this file doesn't exist in your website's home directory, refer to the following articles for instructions on how to create the file using FTP or SSH:
Add these lines to the .htaccess file.
This code also changes the version of PHP you have set in the panel to the version in the second line.
AddHandler fcgid-script .html FcgidWrapper "/dh/cgi-system/php84.cgi" .html
When you load the .html file in a browser, it now loads like a normal PHP file.