0

I am having a problem running my php code from inside an html file. I have tried the .htaccess method and the handler method. I'm using a webserver with cpanel(version 11), apache(2.2.15) and php(5.2.13).I have also tried the files on xampp and they work perfect, but when I upload them to the webserver the php code from inside the html will not run. Any suggestions, please?

3
  • Can you show what you've tried? Commented Sep 2, 2010 at 16:27
  • If it works in XAMPP then your server doesn't support it. Can you talk to your service provider? Commented Sep 2, 2010 at 16:28
  • Are you sure that the web server has .htaccess files enabled? The service provider might have disabled it, you know. Commented Sep 2, 2010 at 16:52

2 Answers 2

4

You need to inform Apache that files of type 'html' need to be parsed by PHP. You can do this by adding this to the Apache configuration file (httpd.conf):

AddType application/x-httpd-php .html

However if you have other HTML files I would advise just rename the file to PHP (or set up some internal mapping so you don't specify an extension all together). If you have static HTML files that you serve, it's redundant to have them being executed by the PHP interpreter.

Sign up to request clarification or add additional context in comments.

2 Comments

The thing is I don't have acces to the httpd.conf file, just the .htacces file and Cpanel's Apache Handlers, where I could modify how apache handles certain files.I will probably have to make it a php file, because it kinda seems like a dead end.
If you have MultiViews enabled you can also ditch the extension and Apache will automagically pick up a PHP file with that name, eg: domain.tld/foo will have a foo.php file (in the document root) being parsed. More on MultiViews here: httpd.apache.org/docs/current/… You can enable MultiViews in your .htaccess file I think: Options +MultiViews
1

Why don't make it a PHP file and then rewrite PHP extension with HTML in .htaccess?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.