
02/062013
Why would I want to parse PHP in HTML files?
For example let’s suppose you have dozens of html files that have the exact same navigation or footer. When you update the menu you don’t want to go and edit all the static HTML pages of your website. So you use an include that will add the menu from a PHP file, and when the menu needs to be changed you will only have to update the php file.
<html>
<head>
</head>
<body>
<div>
<?php include(“menu.php”); ?>
</div>
</body>
</html>
Sometimes, in order to use this awesome php inclusions you need to tell your apache web server that html files can have php code in them, in other words to parse php in html files. This can be achieved by adding some code to the .htaccess file. This file can be found in the www directory that will most commonly be found at this path:
/home/[user-name]/public_html
If the .htaaccess file is not there, create a blank text file using your favorite text editor (mine is PSPad) and upload it to the www folder after adding the following lines in .htaccess:
AddHandler php5-script .php .html .htm
AddHandler application/x-httpd-php5 .htm .html
Make sure the filename contains the dot!
Parsing PHP In HTML when using Godaddy Hosting
Even though I prefer HostGator, I have used Godaddy’s hosting many times, and have had difficulties trying to parse PHP in HTML with Godaddy. But I have recently discovered what the contents of the .htaccess file have to be when using Godaddy:
Options +ExecCGI
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php5 .php .htm .html
10 Comments
After 2 days of struggle, adding following lines worked for me:
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
If you are including any .shtml files thrugh PHP include directive in your html code then add .shtml in AddHandler:
AddHandler fcgid-script .html .shtml
On Whois Hosting (whois.com) I copy this 2 rows on .htaccces, and works very good
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
————–
Test it on http://neculaifantanaru.com
Tried all other solutions. None worked. I am using a dedicated server with godaddy which uses centos and plesk control panel. Here is the final solution I’ve found:
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
Options +ExecCGI
allow from all
This information is adapted from the following information contained in /var/www/vhosts/yourdomain.com/conf/last_httpd.include for the .php extension:
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .php
Options +ExecCGI
allow from all
Thank you!! I tried forever to make this work and couldn’t find any information that actually helped. This worked perfectly!
Now Godaddy’s PHP version is updated to 5.4. Switching to 5.4 will affect this setting? OR above tricks works with PHP 5.4?
Thanks
as of 2014, If you have a godaddy deluxe edition (linux) here is the .htaccess file that will allow you to parse php into html files (using include/require)
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
hope it works out for you.
I tried what you recommended and it works but not they way it is supposed to work.
works, nevertheless, any embedded HTML is not displayed at all. Any ideas?
This method works perfect with Godaddy hosting.. have tried nearly every other methods and didn’t work for me.. thank you very much..
Thanks! It’s work!
Works like a charm!!! Days wasted fixed in seconds!!!!