Jump to content

Trouble in getting php to parse html files

Go to solution Solved by requinix,

Recommended Posts

I'm not 100% sure if this is a server problem so I apologize if this ends up in the wrong thread. So I moved websites from an old server to a new one and everything is working perfectly with the exception of parsing PHP in an HTML file. 
for instance the following will only work if its in a .php file not an html, otherwise it just pushes the
<?php echo "hello world"; ?>

..which tells me that PHP is on and working, but not parsing HTML. I googled and read as much as I could on here about this, and the only thing that I can find is alterations to the .htaccess file to make this work. I already had a .htaccess file, but maybe now it need altering?


I currently have (and it looks messy) this... which worked on my old server and I am assuming old PHP software. I am currently running PHP Version 5.5.20.


A snippet from my .htaccess

AddType application/x-httpd-php php html
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
<Files yourpage.html>
AddType application/x-httpd-php .htm

I have found a bunch of alterations to this online, but nothing appears to work so I thought I would ask the experts. Again PHP seems to work, but only if the extension is .php which I do not want in this situation. Thanks for any help!


Link to comment
Share on other sites

What you do depends on the server configuration. Have you asked your hosting provider yet?


And a correction:

..which tells me that PHP is on and working, but not parsing HTML.

What it tells you is that PHP is not executing that file. Says nothing about whether PHP is "on and working" or whether it is "parsing HTML" (whatever that means).

The actual reason is generally (a) PHP isn't installed or (b) PHP isn't set up to execute files with that extension.

Link to comment
Share on other sites

  • Solution

The recommended way of setting up PHP in Apache is with

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
To include .htm/l files you can modify that to

<FilesMatch \.(html?|php)$>
    SetHandler application/x-httpd-php
Remember to restart Apache if you're putting this in the global server configuration (which you should).
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.