Allow PHP code to execute in a HTML file

By default on Apache web servers, PHP code will not execute in a file that does not have a .php (or similar) extension. So even though you can embed PHP into a HTML file, it won’t execute when the file extension is .html, .htm etc.

To change this, you can add a .htaccess file. Here’s some example code to add depending on your system:

AddType application/x-httpd-php .html .htm

For certain hosting providers you may need to do this:

Addhandler application/x-httpd-php5 .html .php

Put this in a file called .htaccess in the same folder as your HTML files.