Running PHP code in a file with an .html extension


Normally, when PHP and HTML are combined in the same file, the file uses a .php extension and displays data in the browser. For example, this file is named hello.php.


  echo "hello";


However, if you need to place PHP code in a file with an .html extension, you must add a Handler to your .htaccess file for the PHP code to function.

Custom file extensions

You can use the examples in this article for any file extension you like. For example, the file extension .test does not exist. But if you create a file named myfile.test, you can force it to run as PHP.

Just change the code in the .htaccess file to use the extension .test instead of .html.

Create an .htaccess file

The file you need to add code to is named .htaccess. If this doesn't exist in your website's home directory, view the following articles for instructions on how to create the file using an FTP or SSH client.


Add the following line to the .htaccess file to use FastCGI for PHP:

AddHandler fcgid-script .html
FcgidWrapper "/dh/cgi-system/php82.cgi" .html

If you load the file in a browser, it will now load like a normal PHP file.

This code also changes the version of PHP you have set in the panel to the version in the second line.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?