Jump to content
  • 0

Apache config for html/php parsing


Question

I have HTML files created for my Apache server that have some PHP in them like this:

<?php include "includes/topmenu.inc"; ?>

This works just fine if the file is named with the .php extension but it does not work with extension .html.  I had this working on another server that crashed a while back and now I'm stuck trying to remember what I did in the httpd.conf file to make this work.  I tried adding this -

LoadModule php7_module modules/libphp7.so

but then the httpd would not start.  I did a  phpinfo and did not see a HTTP section.

I'm running:

CentOS Linux 8.1.1911
Apache 2.4.37

PHP 7.2.11

Any help is greatly appreciated.

Gene

httpd.conf

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi,

Default configuration on CentOS 8 should work. I didn't do anything other than installing LAMP server on CentOS 8. No modules were added or removed.

I can import .html and .inc extensions just fine as you can see in the screenshot below.

image.thumb.png.62ecfade8ea0f3f160e8fae8c1f40220.png

 

 

I've include the phpinfo() output of my CentOS 8 machine. You can compare it with yours and may find out what modules you're missing maybe.

You may try to enable error reporting on your PHP script. So, if the file you're trying to input does have any syntax error, it should show up. It may help debugging the issue.

 

Wish you all the best.

Shovon

 

phpinfo().html

Link to post
Share on other sites
  • 0

Thanks Shovon,

I agree the default CentOS 8 install works and does import .HTML, . CSS, or .INC files when the file name extension is PHP.   It does NOT import them when the file name extension is HTML.  The example above is from one of the working files from that server (I had most of it backed up) and was contained in an HTML file and correctly imported the contents of the menu for the document.

So, if anyone out there knows what to do to make Apache correctly parse the PHP contained in an HTML file, I'd really appreciate the help.  (I'd rather not have to redo all of my website files into PHP from the current HTML formats.

Gene

 

Link to post
Share on other sites
  • 0

I've mixed php and HTML and named the file test.html. I was still able to import it using include() function and it parsed the php and html contents correctly.

If you change only the extension, I think it will solve your problem. You don't have to convert it to anything. As far as I know, php file can have HTML contents and you can include php code using <?php /*php code goes here*/ ?>

Hopefully someone can help you.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...