• GoDaddy Community
  • VPS & Dedicated Servers
  • VPS & Dedicated Servers

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Go to solution

    Running php in html files

    Does anyone know the magic words to add to the .htaccess file in the root directory that will allow execution of php code in html flies? I tried the obvious from apache forums (AddType application/x-httpd-php .htm .html) but it did not work on the GoDaddy server. However, it did work on my localhost XAMPP server. Any ideas out there?

    41 REPLIES 41
    Community Manager
    Community Manager
    Solution

    Re: Running php in html files

    Hey @geezerman

    Thanks for posting on GoDaddy Community!

    To run HTML using FastCGI/PHP, try adding this code to the .htaccess file for the directory the script is in:

    Options +ExecCGI
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

    You can add additional lines for other file extensions if needed.

     

    Does anyone else in the Community have additional suggestions?

     

    JesseW - GoDaddy | Community Manager | 24/7 support available at x.co/247support | Remember to choose a solution and give kudos.

    Re: Running php in html files

    Jesse,

     

    I put the code in the .htaccess file and it worked immediately. Thanks for the quick AND accurate response.

    New

    Re: Running php in html files

    Hello geezerman,

     

    Just curious, is there a reason you don't just use the .php file extension instead of using .htaccess?  Without needing .htaccess, you can simply use appropriate file extensions.  For example:

    1. .html (html and css)
    2. .css (css only)
    3. .php (html, css, php, and more)
    4. etc.

    Re: Running php in html files

    This does NOT work for me.  Nor does anything GoDaddy support suggests I try or anything I find on the Interwebs.  What else needs to be done to get this to work???

    Re: Running php in html files

    I tried the suggested codes below but it still does not work.  It seems the GoDaddy server still ignore the php code inside htm file.  Any suggestion will be very appreciated.  Thanks!

     

    Options +ExecCGI
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

     

     

    Re: Running php in html files


    @JesseW wrote:

    Hey @geezerman

    Thanks for posting on GoDaddy Community!

    To run HTML using FastCGI/PHP, try adding this code to the .htaccess file for the directory the script is in:

    Options +ExecCGI
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

    You can add additional lines for other file extensions if needed.

     

    Does anyone else in the Community have additional suggestions?

     

     

     

     

     

     

     

     

    when i use this code then my hole page has been blank and its show Resource id #3 error in page

     


     

    Re: Running php in html files

    Finally!!   After perhaps more than 40 hours of searching the web, and W3schools.com, I have been able to run a wee bit of php code!  Now I can progress towards including both javascript and php coding to accomplish some specific tasks.  Your posting is the simple key that has unlocked a door that seemed to be three foot thick solid steel!     Thank you!

     

    I am not exactly a "novice" as I started programming in FORTRAN in 1964.  It has been only in the last three months that I decided to learn javascript and php to modify my websites.  I recognize quite well that it is impossible to keep current in all languages used by computers, and just expand my knowledge as needed.  Too many "helpful sites" assume the reader already has a working base knowledge such that only a snippet of code is necessary to answer questions.

    Helper II

    Re: Running php in html files

    @jameswang63 and @JimSelleck,

    Are you two still having trouble getting this to work?   If so, perhaps I could help you a bit...

    Re: Running php in html files

    I have been able to get .html files to run through the PHP preprocessor easily on ANY other shared Linux hosting system, but not on GoDaddy. It appears to be prohibited, although the advanced techs say it should be possible, in my experience it is not. I have had to move several sites to other shared hosting providers because of this limitation at GoDaddy. If you have a magical workaround, I'd love to learn about it.
    Helper II

    Re: Running php in html files

    @JimSelleck,

    Can I ask some questions?   What flavour of Linux are you running?   I've had some of my questions moved here, although I was running CentOS 6.8 and was renting a VPS from GoDaddy, not a Cloud Server.

    Do you have cPanel installed?

    Finally, what web browser do you use to view your website?   I know there's an issue with Chrome behaving differently than other browsers when it sees the no-cache meta tag.   For example, with my server, I used the old method of telling the browsers not to cache the server.   This worked fine in Firefox and IE, but Chrome would always pull a cached version of the site.   I'm wondering if you're running Chrome and accessing a cached .htaccess file.

    Do you think you could copy and paste the contents of your .htaccess file (at least the parts that deal with PHP)?   Also, perhaps you could run ls -l on it so we can see the file permissions.

    Thanks.

    Re: Running php in html files

    I am a little lost too.  I had my PHP working a few months ago but now all I get is a blank white page.

    I did check the .htaccess file and it appears to be ok.. here it is..

     

    AddType video/ogg .ogv
    AddType video/mp4 .mp4
    AddType video/webm .webm
    AddType application/x-httpd-php .htm .html

    # 1 Month for most static assets
    <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
    Header set Cache-Control "max-age=2592000, public"
    </filesMatch>

     

    I found this part in this thread and added it too.. but no luck.

     

    Options +ExecCGI
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

     

    and I am not getting my "connecting to database.." text right before the PHP executes either.  If I try to display the source code of the blank white screen all I get is an empty file with one line and no characters at all, as if it loaded a blank page.  I reinstalled my .htaccess and the HTML file with the php code but nothing is working. I even tried changing the rights of .htaccess to 0755.

     

    I don't know what changed since it was working before.  I am thinking its something on the .htaccess side because the HTML script has not been touched.   Any ideas?

    Re: Running php in html files

    Options +ExecCGI
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

    This caused me an internal server error? Anyone else?

    Re: Running php in html files

    This causes a server error for me too

    Re: Running php in html files

    Adding this to my htaccess file results in a server error. Is it possible that there's a difference in some hosting accounts that prevents this from working? I have a Linux account that's been open for at least 10 years, so is there any chance I'm on an old configuration or something?

    New

    Re: Running php in html files

    adding the code to htaccess file didnt work for me either, Can anyone give a solution pls




     

    Sorry, this file type is not permitted for security reasons.

    I'm getting this notification on my Wordpress media uploader:  " Sorry, This File Type Is Not Permitted For Security Reasons."

    It's an .ogv file, which I've not only used on this exact host set up before, but also on this very site!

    I'm not sure why this is not working all of a sudden. Can anyone please explain why this would have happened and how I might go about fixing it?

    Cheers. 

    Re: Sorry, this file type is not permitted for security reasons.

    Hi Guys, 

    Have the same issue with PHP not displaying in my .html pages. I have the following code inside my .htaccess file:

     

    AddType text/html .shtml .shtm .htm .html
    AddHandler server-parsed .shtml .shtm .htm .html
    Options Indexes FollowSymLinks Includes
    Options +ExecCGI
    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

     

    Any suggestions .. 

    Re: Running php in html files

    Hi,

    I had faced the same issue when i uploaded my .html files having php code inside. IT hsa phpi have tried doing below things and it worked.

    1. Go to cPanel, click on Service Configuration , click on Configure PHP and suExec

    2. check if the handler is set for your .php files and then save the confiuration

    3. It will then restart the apache instance. conf file is available at /usr/local/apache/conf/

    4. look for php5.htaccess 

    5. add below entry in php5.htaccess file

    AddHandler application/x-httpd-php5 .php .html

    6. then copy the contents of this file across all important directories where you have kept .htaccess files

    7. restart the apache instance and you are done.

    Re: Running php in html files

    I added this to the .htaccess in my 'www' home directory and it seems to be working:

     

     

    AddHandler fcgid-script .html
    FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

    and using the Godaddy admin web ui, you would just add an 'Apache Handler' (way down at the bottom of the cpanel/admin ui) of type 'fcgid-script' with extension '.html' -- that does the same thing.

     

    i would upload an image but this godaddy uploader is broken.

     

    New

    Re: Running php in html files

    These three lines worked for me:

    (Delux Linux Web Hosting)

     

    Options +ExecCGI
    AddHandler x-httpd-php5-cgi .html
    AddHandler x-httpd-php5-cgi .css

     

    Before my most recent GoDaddy (theoretically invisible) server upgrade, just the latter two worked fine, but it took me much futzing and searching to discover that I now also apparently need the first line. (General global thanks to all that suggested the ExecCGI and fcgid-script lines. That solution resulted in nothing but " mod_fcgid: error reading data from FastCGI server" errors for me, but it was eventually enough to help me dissect and gleam just the first ExecCGI line. )

    Re: Running php in html files

    OH WOW, thank you for this!  I am running an angular app on godaddy and decided to learn how to get the URLs to show without the hash.  Well, I'm pretty new to all of this, so I was all proud of myself for figuring that out, but then I discovered that I'd get a 404 error whenever I refreshed a page with one of this nice clean URLs. Figured out why (essentially i was restarting the app and trying to go inside of it at the same time...if that makes sense) fixed that. Then the PHP file that was running my contact form suddenly became 403 forbidden and I could not for the life of me figure out the proper HTACCESS magic words to fix it. This did the trick! Thanks!

     

     

    Re: Running php in html files

    None of the settings above worked for me. 

    Does anyone know the correct lines to enter in .htaccess for GoDaddy Shared Linux Deluxe Hosting running PHP version 5.6?

     

    GoDaddy migrated my sites to a new shared webhost without notifying me first, and it caused this issue.

     

    Thanks in advance!

    New

    Re: Running php in html files

    I encountered a related problem while attempting to add a redirect for my https site using the cpanel. When saving the redirect I get the following error message.

     

    “There was an error adding the redirect. Apache detected an error in the Rewrite config. <pre>AH00526: Syntax error on line 14 of /home/primawebsite/public_html/.htaccess.Ll2RgeBsngIhGuD1CuYhEszPaZ3yxr7j: Invalid command &#39;FCGIWrapper&#39;, perhaps misspelled or defined by a module not included in the server configuration </pre> Please try again.”

     

    When I comment out the offending line “FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html“  then Apache returns the following error when I reload the page.

     

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

     

    However, those three directives are the only way i've been able to get apache on godaddy linux to process html files as php. 

     

    On other linux server I just use the following directive in the .htaccess or the vhost configuration for the site.

     

    AddType application/x-httpd-php .html

     

    How can this problem be resolved?

     

    Re: Running php in html files

    Same here but just recently after GoDaddy apparently updated or changed the server on my client without notifying them. Which I see other complaining about as well. A big no no and is unacceptable practice in my opin ...

    I see that the 2 lines that are mentiond

    Options +ExecCGI
    AddHandler x-httpd-php5-cgi .html

     

    Almost work but not quite because on submit the form in the HTML based page causes internal server err, but only on submit so go figure, and I must say this problem is Unique to GoDaddy as I work with a lot of dif servers and this never happens ever. And as noted worked fine until they did whatever they did when the did it. Most likely because of all this CGI Wrapper nonsense they seem to love.

    Also I note that sessions do not work as they should on this new server either. So others my find that to also be an issue. We want some 3rd Lev Techs on this ASAP as you have many issues, and we need answers to the problems created from your upgrade.

    I would like a response from 3rd Lev, I have dealt with many of you in the past you also have my e if you want to contact me directly. (Note: it shows me as novice but I am not a Novice)

    New

    Re: Sorry, this file type is not permitted for security reasons.

    I had similar problem when i transferred my website from xampp to godaddy, i sugest you to chech in php settings if you have correct php version, and if not than just change. i changed from php 7.1.1 to php 5.6 

    Solution

    Re: Running php in html files

    20170903  This just worked for me:

     

    Options +ExecCGI
    AddHandler php5-script .php .html .htm
    AddHandler application/x-httpd-ea-php56 .html

    Specifically, if you login to server as root and go to 

       /usr/local/cpanel/cgi-sys/* you will see the different versions of php on your

    machine.

     

    Write a one line script issuing the phpinfo() command to see what version you are actually using

    Re: Running php in html files

    Thanks man!!!

     

    Originally I had only:

    AddHandler x-httpd-php5-cgi .html

    but I kept receiving "Forbidden You don't have permission to access /xyz.html on this server.".

     

    After adding this line first:

    Options +ExecCGI

    everything started working as a charm (I did not need the same for CSS)!

     

    Thanks again!

    New

    Re: Running php in html files

    sometime in the last 24 hours Godaddy stopped running php on my html pages. 

    The php lines (which obviously should not be seen) are commented out.

     

    I have an old site with much link mojo and have been adding php code to my .htm and .html files. Any new files of course are named .php. The Godaddy servers have always been able to run php in my htm pages. This is not a new problem (although each server they move me to has variations in how to do it).

     

    2 months ago they convinced me to transfer my site to the latest and greatest CPANEL Ultimate?Hosting . (I din't find out until after the move that this is shared now.)

     

    I am running php 7.1 on linux Cpanel.

    This .htaccess code worked until yesterday (12 June 2018)

           Options +ExecCGI

           AddHandler fcgid-script .html .htm
           FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .htm
           FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

     

     

    Do I need to change the php5 to php71  to restore functionality?

    Do I need different code? What did Godaddy change?

     

     

    By the way, phone support was no help. He said this code would crash the server and shouldn't have worked at all. There is no way to do this. There are no errors showing so its a coding problem with my website and he needs to move on.

    Re: Running php in html files

    I have a similar situation to sgw

    Six months of operation with php includes, and today when I open the site, none of them work, nor do they provide an error message.  Obviously, something was changed on the Godaddy side.  

     

    Re: Running php in html files

    Another post on the same topic elicited this:

    "Haven't changed anything on our site since 2017, down today due to non parsing of embedded php. I now see a banner at the top of cpanel saying our server has changed, without notice.. Thinking this is why my php is now broken.. I think I'm going to switch hosting, this is ridiculous!"

    gulfwebs, I appreciate the offer, but after plowing thru a myriad of different measures others have proposed to get either php includes or server side includes to work, none of them were effective for me, and I seriously doubt that a phone call could fix this.  I have other webspace in another host, and they don't seem to have this "feature" there.

     

    Re: Running php in html files

    I just recently solved all my problems with GoDaddy - I simply switched to another company!!!

     

    I feel like I took of my very tight shoes I wore for years. What a relief!!! 🙂

     

    After thorough research on best hosting companies, I narrowed my favorites to four, then two companies (SiteGround and InMotion). Finally, I decided to switch to SiteGround for the next two years.

     

    Everything is much, much better now - sites are blazing fast (SSD drives), FTP and databases are muuuch faster, number of emails is unlimited (both POP2 and IMAP), many more options and control and, most importantly - great support. You can create tickets from the cPanel, but I prefer chatting. Even when I was not their user, the response was quick and professional. You can give it a try - go to their site, start a chat and see for yourselves.

     

    Currently only my domains are with GoDaddy. I think they cannot screw much there, since all are "redirected" to SiteGround now.

    New

    Re: Running php in html files

    I'm also having this exact same issue. A couple days ago everything was fine, today I got a report from a customer that our site wasn't working and discovered this problem. If the code is in a .php file it runs, but all the .html files containing PHP are no longer interpreted, and I can't find any working combination of what to add to a .htaccess file to get them working again.

    New
    Solution

    Re: Running php in html files

    After about an hour of hair-removal, I found a thread on Stack Overflow addressing this problem.

     

    Check here for the details: https://stackoverflow.com/questions/50731370/addhandler-htaccess-on-godaddy-stopped-working-today/50...

     

    That gave two suggestions, and based off of those, this is what I changed my .htaccess file to contain:

    Options +ExecCGI
    AddHandler application/x-httpd-lsphp .html

    I then reloaded a html page, and the php was once again being processed.

     

    Posting here in hopes that this will help others! 

    New

    Re: Running php in html files

    WOW. THIS WORKS.

    It's too bad the Gadaddy 'tech' couldn't have told me this instead of belittling my site's coding and having to 'move on' to the next caller if I couldn't produce an error message.

     

    Here's a workaround I started using in desperation:

    1. rename all .html and .htm to .php

    2. add this to .htaccess:

         RewriteEngine on
         RewriteRule ^(.*)\.htm$ $1.php
         RewriteRule ^(.*)\.html$ $1.php

     

    Although Tdcook found the solution to this month's Godaddy feature update, I must say I am going to go with adlabac's more permanent solution.  Thank you both.

    New

    Re: Running php in html files

    I had the same problem. This solution posted by (novice) tdcook worked for me. The solution posted by godaddy customer service (experts) were a waste of time.

     

    Options +ExecCGI
    AddHandler application/x-httpd-lsphp .html

     

    Solution

    Re: Running php in html files

    Although this is def on the correct track I found that some of the GoDaddy servers run unstable with that code and will crash on page re-load. I found that this works well on a GoDaddy server where the other may be unstable. So for some that may have issues with the code you posted they may want to try this. As we all know here its a crap shoot ... But this could work for some.

     

    #2018 Lets parse html via php
    Options +ExecCGI
    AddHandler x-httpd-php .html .htm

     

    Re: Running php in html files

    tdcook, Thank you so much. That worked.

    Btw after adding the line you mentioned,

    AddHandler application/x-httpd-lsphp .html

    I had to remove this existing line from my .htaccess file:

    AddHandler fcgid-script .html .shtml

     

    Again thank you for your research in finding a solution for this problem.

    Re: Running php in html files

    This worked for me. Thanks a lot!

    Re: Running php in html files

    Thanks, you save my site

    Re: Running php in html files

    After two days of pulling hair I found your post and tried it.

     

    Options +ExecCGI
    AddHandler application/x-httpd-lsphp .html

    It worked! Thank you!!! I am using PHP 5.6 which at this writing is the latest php 5 version Godaddy supports. I'm going to try using php 7. If this code works or not I will get back to you.

    Re: Running php in html files

    Options +ExecCGI
    AddHandler application/x-httpd-lsphp .html

     

    This definitely worked for me .

    Thanks

    @Danamo and @tdcook 

    I started to get worried that my site wasn't gonna work since it was taking me so

    long to get this issue resolved. Thanks again