Page 1 of 1

php scripts in html not working

Posted: Sun May 27, 2007 8:57 pm
by dpsthree
This is my first time working with PHP and Apache and I'm having a bit of trouble.

Im running apache 2.2.4
PHP 5.2.2
and Windows Vista/XP (Installed on both)

I'm sure this is going to be something simple, but hours of looking hasn't turned anything up yet.
the following is in an .html file

Code: Select all

<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
when opened in a browser it gives me a blank screen, but renaming it to .php works, how do I get the html to pick up the php tag?
I used the alternative, <script language = "PHP"> with similar results.

PHP is installed properly as using phpinfo() works correctly from a .php file.

Any help would be greatly appreciated.

Posted: Sun May 27, 2007 9:55 pm
by superdezign
Well, most PHP website use the php extension. We're generally proud to use PHP.

However, you're welcome to use a HTML tag, but you have to define in your Apache configuration for *.html files to be treated as PHP files.

Posted: Mon May 28, 2007 2:21 am
by dpsthree
The reason I ask is because I have taken over a project started by somebody else whom I have no way of contacting, and he has used the .html extension on his files. Upon digging a bit deeper, I realized that his files not working was only a secondary problem and I can't even get the simplest of scripts to work in html. Its more a matter of knowledge then preference.

As for fixing the problem, I'm assuming you mean that I have to edit the httpd.conf file, but how?

Thanks for the response

Posted: Mon May 28, 2007 7:55 am
by feyd
Poke around for the term "AddType." ;)

Posted: Mon May 28, 2007 2:16 pm
by califdon
Unless you have a particular reason not to use .php file extension when you want PHP to parse a file, you shouldn't reconfigure Apache. If you do, it will require that every .html file be examined by PHP to see if there's any PHP code in it. No reason to do that, normally.

Got it

Posted: Mon May 28, 2007 3:12 pm
by dpsthree
Awesome I got it working. I added:

AddType application/x-httpd-php .html

califdon wrote:Unless you have a particular reason not to use .php file extension when you want PHP to parse a file, you shouldn't reconfigure Apache. If you do, it will require that every .html file be examined by PHP to see if there's any PHP code in it. No reason to do that, normally.
thanks for the insight, I'll be sure to set it back once I figure out what the previous coder has done with his work, and change it over to .php

Thanks everyone