3

Apache2, Linux, php5

I have added this line to my .htaccess file

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

running apace2ctl -m, shows this module loaded

A php5_module (shared)

I have a simple HTML page with one line of PHP code inside an <h2> tag

 <?php echo "It works!"; ?>

When rendered in the browser the server appears to have commented the PHP out like so

<!--?php echo "It works!"; ?-->

If I rename the file with a PHP extension it works fine.

Why won't Apache process the PHP code in my HTML files as directed? What am I doing wrong?

0

3 Answers 3

3

<!--?php echo "It works!"; ?-->

This is what you see when you analyse the element using the browsers Object Inspector ie. the interpreted source. This is not the HTML source as sent from the server (ie. "view source").

Basically, your HTML pages are not being processed by PHP. You probably need to check with your host as to the correct directive to use. You may need to use AddHandler instead, or drop the 5, or something else. (That is if your host permits these directives in .htaccess?)

2

My apache installation has a php5.conf file I added this to it.

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

In my .htaccess file I also changed

AddType application/x-httpd-php5 .html

to

AddType application/x-httpd-php .html

Scott

1

It's usually better to just use a php file instead of an html file for what you're trying to do. However, if you absolutely need it to be an html document, you can use an .htaccess file placed in the root of your site containing this:

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

Instead of

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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