2

How can I make apache parse php code inside my html pages? I don't wanna use .htaccess. I've added:

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

in my vhost file for one of the websites but it won't work.

2 Answers 2

3

I have the same problem in the latest versions (Debian 10 , Apache 2.4.25, PHP 7.0.33)
My solution is edit the php.config file, to find it I put:

find -iname php*.conf

...and in my debian instalation I found it in:

 /etc/apache2/mods-available/php7.0.conf

Then, I introduce those lines at begining:

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

And it work for me.

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

Comments

2

Did you build your Apache binary with PHP? Or if you built a SO, reference it in the Apache config (e.g.: LoadModule php5_module modules/libphp5.so)?

When using .html for PHP, ensure 'AddType text/html .html' is removed, so it doesn't conflict with the x-httpd-php reference.

FYI -- you can create one entry 'AddType application/x-httpd-php .html .php'

2 Comments

Hi Jerry. Thank's for answering. Well ... apache and php are already working together. The code in *.php pages is being parsed. So, the php pages are working. Anyway, I've finally manage to get it working ... there was a "AddType text/html .html" declaration somewhere in the hosts configs which I stuppidly missed. After removing that it now works. The html pages which contain php code are getting processed.
That would explain it. It was conflicting with the that line. I will update my answer for others. Good find!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.