php scripts in html not working

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
dpsthree
Forum Newbie
Posts: 3
Joined: Sun May 27, 2007 8:19 pm

php scripts in html not working

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
dpsthree
Forum Newbie
Posts: 3
Joined: Sun May 27, 2007 8:19 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Poke around for the term "AddType." ;)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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.
dpsthree
Forum Newbie
Posts: 3
Joined: Sun May 27, 2007 8:19 pm

Got it

Post 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
Post Reply