Add php code to .html file types

I wanted to add some php code to an existing static html page. But I noticed that the PHP content didn’t render on the browser in the first place. It would only work if I renamed the file extension from .html to .PHP.

In order to have the php content work in an HTML file extension, the following piece of configuration is required within the .htaccess file on your server. This can be created on the site’s root directory and the properties are inherited by all the sub-directories.

AddType application/x-httpd-php .html

In order to enable PHP within HTML code on a Mac,

vi /etc/apache2/httpd.conf

Look for <Directory “/Library/WebServer/Documents”> and change AllowOverride None to AllowOverride All

Restart apache and you should be all set.

sudo apachectl restart
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s