• 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?

    4 ACCEPTED SOLUTIONS
    Community Manager

    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.

    View solution in original post

    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

    View solution in original post

    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! 

    View solution in original post

    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

     

    View solution in original post

    41 REPLIES 41
    Community Manager

    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.

    View solution in original post

    Jesse,

     

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

    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.

    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???

    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

     

     

    @jameswang63 and @JimSelleck,

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

    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.

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


    @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

     


     

    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.

    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?

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

    This caused me an internal server error? Anyone else?

    This causes a server error for me too

    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?

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




     

    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?

     

    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)

    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. 

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

    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