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?
2 Answers
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.
2 Comments
Vidi
 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.
  Peter Kruithof
 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
  
.htaccessfiles enabled? The service provider might have disabled it, you know.