Sometimes we need to parse HTML or other files as PHP. This can be done using either apache2.conf or httpd.conf whichever applies to your Apache Web Server or by using .htaccess file placed in your root web document directory.
We will discuss .htaccess file as it is the best and easiest way to achieve this feat. I am currently running Ubuntu 14.04 which has the root directory in /var/www/html. Now perform the following steps in order to enable the HTML file processing:
- Create a file by name .htaccess inside the /var/www/html
Write the following inside the .htaccess file
AddType application/x-httpd-php .html .htm
Save the file
Open apache2.conf or httpd.conf and find the section <Directory /var/www/html>
Modify the line AllowOverride None => AllowOverride All
Save the file and restart apache2 webserver
That’s all you are done with it. Now your html or whatever extension files you wish can process the PHP inside it.