PHP DOESN'T WORK!!!

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP DOESN'T WORK!!!

Postby zeuser » 04. April 2010 04:27

Hi All,

First of all: Why isn't xampp setup to work with php right out of the box? Considering the number of people I see all over the web complaining that their PHP just doesn't work, it would seem a no brainer if xampp would be properly configured to do this right from the start. Especially for those of us who use the defaults from the install. I mean really... follow the default installation options and... IT DOESN'T WORK?

Ok... enough ranting.

So I created a simple test document called c:/xampp/htdocs/test.html which is nothing more than:

<?php
print "Hello world";
?>

I then try to open it with Firefox and IE at the following address: http://localhost/test.html and what happens?
NOTHING!

However, if I write the same code into a test.php file and use http://localhost/test.php , it does work.

Viewing the source shows the document I typed so it did locate the document but the PHP interpreter just didn't work.

Oh and I disabled Skype as it caused issues (port 80). Apache is up and running, it just refuses to execute php code embedded in a html file.

PS: I've been a computer programmer for 20 years now, mostly Business Basic and VB, so don't be afraid of using programmer terminology. I'm new to PHP and Apache but not computing.

Thanks for the help.
zeuser
 
Posts: 4
Joined: 04. April 2010 04:14

Re: PHP DOESN'T WORK!!!

Postby zeuser » 04. April 2010 05:09

Just a follow-up, this document is what's not working when I type http://localhost/test.html in the address bar.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title>
test
</title>
</head>
<body>

<?php
PRINT "hello world!!!";
?>

</body>
</html>

It does pass the html validator so no problems there. It's clearly apache not sending the php piece to the interpreter.
zeuser
 
Posts: 4
Joined: 04. April 2010 04:14

Re: PHP DOESN'T WORK!!!

Postby zeuser » 04. April 2010 05:24

FOUND IT!!!!

Yup, just what I thought: xampp isn't properly configured "out of the box".

This line was missing from c:\xampp\apache\conf\httpd.conf

AddType application/x-httpd-php .html

Just search the httpd.conf file and look for this line:
<IfModule mime_module>

You'll notice a few "AddType" in that block. Just add the proper "AddType" above in the block and it'll work.

Note to xampp developers: Please add this into the default configuration so that noobs like myself don't waste 5 hours hunting for the solution across the web. Thank you.
zeuser
 
Posts: 4
Joined: 04. April 2010 04:14

Re: PHP DOESN'T WORK!!!

Postby Altrea » 04. April 2010 07:47

zeuser wrote:xampp isn't properly configured "out of the box".

That's not correct. HTML is just a markup language which will be rendered by the client browser. It is the correct way to serve this files as plain text (like the Apache in Xampp does out of the box).
If you need php in your files, than give your files the right file extension! There is NO reason to put php code into html files. Thats just sloppy programming.

zeuser wrote:Note to xampp developers: Please add this into the default configuration so that noobs like myself don't waste 5 hours hunting for the solution across the web. Thank you.

You should try the board search for php code in html. I think you would have found the solution in less than one minute.

And just because a few sloppy programmers want html files parsed by the php interpreter, this should be the standard behaviour of Apache?
What if some users have the great idea to put php code into .txt files? or .css files? or .jgp files?

Configure your own Apache sloppy like you want.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8290
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 69 guests