Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 2 server on ubuntu can't parse php code inside html file

I installed apache2, php5 and the php5 apache module on Ubuntu 13.04.

Php is working on .php files but lines of php code inside html files do not execute.

Googling I found that must add AddHandler... and AddType... lines to httpd.conf but the version installed doesn't have this file or at least can't find it in /etc/apache2/

code example:

<html>
<head></head>
<body>
    <?php 
      phpinfo(); 
    ?>
</body>
</html>
like image 407
Gjaa Avatar asked Feb 06 '26 02:02

Gjaa


2 Answers

Got it to work. my version of apache doesn't have httpd.conf, instead has php5.conf in /etc/apache2/mods-enabled/

editing that file, found this:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler applicatio
    ....
....

added the lines:

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

now php parses the html files and <?php ... ?> code works.

like image 153
Gjaa Avatar answered Feb 07 '26 17:02

Gjaa


You can probably check under /etc/conf/httpd/httpd.conf

Alternatively you may want to use the 'find' command or run 'updatedb' and then 'locate httpd.conf' file.

The issue is unless you add the correct directives in httpd.conf - your php file will be rendered as a plain text file. Hence you wil have to LoadModule && AddType to get it running.

like image 20
Sunil Bhatia Avatar answered Feb 07 '26 18:02

Sunil Bhatia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!