2

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>
6
  • 1
    Obviously if you cannot find those lines that Google is telling you to add, then you add them, restart Apache, and test again. Commented Jul 5, 2013 at 19:05
  • stackoverflow.com/questions/6295141/… Commented Jul 5, 2013 at 19:05
  • @HalfCrazed i said i cannot find the file httpd.conf not the lines. thanks for the reference Commented Jul 5, 2013 at 20:18
  • I'm new here. why negative votes? Commented Jul 5, 2013 at 20:21
  • In your server, you can try locate httpd.conf to get paths to the file I believe. Commented Jul 5, 2013 at 20:38

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

tried looking for that path but no luck. 'locate httpd.conf' get me no file. i already find the solution, will post it as soon as i can.
2

You can probably use a .htaccess configuration file for this.

Create a blank text file and name it .htaccess

(If your operating system does not allow file names starting with a dot just name the file temp.htaccess temporarily. After you have uploaded it to your server, rename the file to .htaccess)

Add the following line into the file:

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

If this does not work, try changing it to:

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

This is assuming that your apache configuration allows for .htaccess files to override the default settings.

1 Comment

thanks for the answer. it's solved already. had to add some lines to /etc/apache2/mods-enabled/php5.conf. will post details soon.
0

Add the following lines in /etc/apache2/mods-available/php7.0.conf SetHandler application/x-httpd-php

this worked for me. Thx Lukjar

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.