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

Running PHP in an HTML file

I'm trying to run a PHP file that is inside of a HTML file. 

 

I tried adding these lines to my .htaccess, but that didn't work. 

 

Options +ExecCGI

AddHandler fcgid-script .html

FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

 

What do you suggest doing?

 

Thanks!

9 REPLIES 9
Anonymous
Not applicable

Re: Running PHP in an HTML file


@ctkgroup wrote:

I'm trying to run a PHP file that is inside of a HTML file. 

 

I tried adding these lines to my .htaccess, but that didn't work. 

 

Options +ExecCGI

AddHandler fcgid-script .html

FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

 

What do you suggest doing?

 

Thanks!


 

 

Hi @ctkgroup,

 

Does your file have a '.html' extension by any chance? If so it won't work, it must have a '.php' extension or the code won't run. 

Re: Running PHP in an HTML file

Yes it is .html. 

 

But I have seen others do it just fine on GoDaddy with .html files. 

 

Is it now not possible to?

 

Thanks!

Anonymous
Not applicable

Re: Running PHP in an HTML file


@ctkgroup wrote:

Yes it is .html. 

 

But I have seen others do it just fine on GoDaddy with .html files. 

 

Is it now not possible to?

 

Thanks!


 

Hi @ctkgroup,

 

I think you are either misunderstanding something about PHP in html files, or are simply not explaining your issue clearly.

Show me some examples of what you are talking about here...............

Re: Running PHP in an HTML file

I'm trying to do what is mentioned in this forum.

https://www.godaddy.com/community/Managing-Web-Hosting/Running-php-in-html-files/td-p/16302

 

It seems to work for those users, but it isn't working for me. 

Anonymous
Not applicable

Re: Running PHP in an HTML file

Hi @ctkgroup,

 

And if you read all the posts I don't think any solution was found, yet I am telling you the solution and you are still unsure? 

 

here is an example, very simple....

<!Doctype html>
<html> 
<body>
<h3>Here is some simple php code to give the date year.</h3>
<?php echo date (Y); ?>
<hr>
</body>
</html>

Now although this file is STILL an html file as seen in 'Doctype html' it will be given the '.php' file extension instead of the 'html' extension as this tells the server to look out for some PHP code in between the HTML. 

 

A FILE THAT IS PURE PHP, doesn't need the '<!Doctype html>' or even the HTML tags (<html></html> but a pure PHP coded file must be linked to the file it is to work in.

 

PHP was always designed right from the very start TO RUN IN HTML files, so it really is nothing special to do this. But we have to tell the server to look out for it and run it if found by adding the '.php' extension. 

 

Re: Running PHP in an HTML file

This is what now works for me in the .htaccess file, since Godaddy upgraded my hosting account this month:

 

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

 

Before the upgrade, only the second line was needed.

Re: Running PHP in an HTML file

DavidRaich, Thanks for figuring out what worked with the GoDaddy site. A recent GoDaddy change had broken my site and GoDaddy support is apparently unaware of this needed change.

 

I have changed the .htaccess file to the following.  Before the GoDaddy change only the AddHandler line was needed.

 

Options +ExecCGI

AddHandler x-httpd-php .htm

 

Cheers!

Re: Running PHP in an HTML file

I've had the same problem. All my websites that processed .html as php are broken. However I've added those   lines but no joy.

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

 

I even changed it to 5-6 as that's the PHP version now but still it displays the php source when I view the source in the browser.

 

Any thoughts?

 

David

 

Highlighted

Re: Running PHP in an HTML file

My site is configured by Godaddy with PHP 5.3, but yours might be with something else. You should be able to check your own site's PHP configurations by adding a file named phpinfo.php to it -- contents

<?php
      phpinfo();
?>

and run it. If that doesn't work, then PHP is not configured right at all for you.

 

I'm not sure how to access other versions. Since changing 5-3 to 5-6 didn't work in .htaccess, maybe you should try just 5, or maybe leave the version off altogether.