InMotion Hosting Support Center

How do I execute PHP code in a HTML page?

Category: How To

2012-02-11 7:18 pm EST

Hits: 26,749
Ultimately, I'd like to insert a short line of PHP to get the current date and format it a specific way.

Right now, if I put PHP into my HTML it sends the PHP to the browser!

I need the server to run the PHP and insert the output into my HTML. What do I need to do?

For example, I added two lines to the 'default.htm' that came out of the box. First line is "TESTING..."
Second line is


When I refresh the page, "TESTING..." shows up, but not "HELLO". If I use the browser to inspect the page source, I see my PHP code.


You must login before you can ask a follow up question.

You must login before you can submit an answer.

Best answer chosen by User


Tim S
13,821 Points
2012-02-13 10:39 am EST
Hi sandiego,

Thanks for posting your question. I'm more than happy to assist you today. You have two options when facing the problem that your PHP code is not executing in an HTML page. Since the web server thinks the page is written in HTML, it does not know to execute the PHP code. You can save the page as a .php file and this should resolve the issue.

Alternatively, if you have a alot of links to that page, changing the file extension will break all the links. You can tell the server in your .htaccess file to execute all HTML pages as though they are PHP. Here's the code to do that:

<p class="code_block">AddType application/x-httpd-php .html</p>

This tells the server to execute all files with the .html extension as a PHP file.

If you are using the .htm extension on your files you'd add this code:

<p class="code_block">AddType application/x-httpd-php .htm</p>

Lastly, if you wanted to execute just one file that's got the extension of .html or .htm as a PHP file you could add this line of code:

<p class="code_block">&lt;Files yourpage.html>
AddType application/x-httpd-php .html

Remember, you'll need to replace the yourpage.html with your actual file name. If you need further assistance please feel free to contact us.


Tim S

You must login before you can post a comment about this answer.

The above didn't work for me. However this did:
AddHandler application/x-httpd-php5 .html .htm
3 Points
2013-04-13 9:10 am EST
Like this Question?

Forum Login

You are NOT logged in. You can still browse our Support Center.

To participate within our Community Support Forum:

Need more Help?

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!