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:

  1. Create a file by name .htaccess inside the /var/www/html

  2. Write the following inside the .htaccess file

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

  1. Save the file

  2. Open apache2.conf or httpd.conf and find the section <Directory /var/www/html>

  3. Modify the line AllowOverride None  => AllowOverride All

  4. 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.

 

Enable PHP in HTML or other files

Leave a Reply