Sometimes we wish to execute PHP code inside the HTML files and allow their parsing to be done by PHP

This can be easily achieved by enabling .htaccess files in the Apache, following steps will help in enabling this:

Open Apache Configuration file and move to the section which contains the directory in which webpages are being served in example scenario we will take /var/www

The following section will be present in the apache.conf

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Modify this section to

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Now open .htaccess file in the folder in which you wish to parse the .html and .htm files as PHP and add the following line

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

Apply the changes to the web server by restarting it using the following command

/etc/init.d/apache2 restart

That’s it – Now all the HTML pages being served by the webserver are automatically parsed by PHP engine.

 

Enabling PHP code in .HTML files

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.