Mobile app version of vmapp.org
Login or Join
Odierno851

: Using PHP inside .html files not working as expected Apache2, Linux, php5 I have added this line to my .htaccess file AddType application/x-httpd-php5 .htm .html running apace2ctl -m, shows this

@Odierno851

Posted in: #Apache2 #Html #Linux #Php

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?

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Odierno851

3 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina238

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

10% popularity Vote Up Vote Down


 

@Fox8124981

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

10% popularity Vote Up Vote Down


 

@Jamie184

<!--?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?)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme