Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For example, echo phpinfo() returns nothing in my .html file

but index.php returns with the info

wich setting needs to be adjusted?

thanks

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You need to configure Apache to look for PHP in html files.

You can use either AddType, or FilesMatch, e.g.:

<FilesMatch \.html$>
    SetHandler application/x-httpd-php
</FilesMatch>

Note this could impact performance, as each HTML file will now be checked for PHP code.

FilesMatch is better then AddType as it'll protect you from some exploits. Details about this can be seen in step 6 of the php install manual

share|improve this answer
    
thanks, I was surprised it did not work because on my hosting-provider it's not a problem –  Richard Jun 1 '13 at 0:25

you can not execute php code in an HTML file, the file needs to be a PHP file with an extension of .php or .php5

In order to execute PHP code inside HTML you will need to add a handler

Enter this in the .htaccess file in the root of your Apache web server

AddType application/x-httpd-php .html .htm

If you're running PHP as CGI:

AddHandler application/x-httpd-php .html .htm 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.