Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have installed an Apache server (version 2.4) on my Windows 10 computer, and then I have installed PHP and edited the configuration files to the best of my ability.
(This is my first time installing an Apache server, so I might have made a few rookie mistakes)

The problem is that PHP code inside a HTML document is not executed, instead the code is commented out.

I try to run this HTML
HTML
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	</head>

	<body>

		<h1>
			<?php echo "My first PHP script!";?>
		</h1>

	</body>
</html>

The result is a blank page.
If I use the developer mode (F12) the code looks like this, so I guess there is no surprise that the page is blank.
HTML
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
	</head>

	<body>

		<h1>
			<!--?php echo "My first PHP script!";?-->
		</h1>

	</body>
</html>


I have tried both to run the file from the browser as a local host, http://localhost:8080, and open the file directly, but the result is the same.

However, if I run a PHP-file directly it works.
I created a file called phpinfo.php and put it in the configured root directory.
PHP
<?php
phpinfo();
?>

Then I use the following link in the browser
http://localhost:8080/phpinfo.php

The result is the PHP-info page.

This gets me a bit stumped as I am new to this and I don't know what else to configure.
I have probably missed some simple configuration, but right now I cannot think of anything else.

Does anyone know what the problem might be and a possible solution?

What I have tried:

I have tried both PHP 5.6 and PHP 7, but with the same result.
I get the same result regardless of browser, Edge, Chrome, Firefox.
Posted
Comments
enhzflep 7-Aug-16 16:53pm    
I haven't changed it in a million years, but I'd imagine it to be found in PHP.ini
Basically, there's a flag that controls whether or not Apache will look inside .html file its serving for PHP code, or whether it will only search in .php files.

From memory, html/php files were both searched by default once upon a time. Somewhere over the past 8 or so years it seems to have changed.

Anyway, here's a couple of answers to the problem:

Parse HTML files as PHP
How to run a php script inside an html file
George Jonsson 7-Aug-16 23:59pm    
Thanks a million. The change has to be made in hpptd.conf or .htaccess, but otherwise you were spot on.
I had to add the following lines inside the block <ifmodule mime_module="">
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
Then it worked like a charm.

You should submit this as an answer, so other people can benefit from it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900