Jump to content


Photo

Apache works, but doesn't parse PHP


  • Please log in to reply
9 replies to this topic

#1 Imark

Imark
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 July 2006 - 03:57 AM

I installed the PHPDev5 package with PHP, Apache, MySQL and what not.

I put a "Hello world!" in the www directory like this:
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Hello World</p>'; ?>
</body>
</html>
Now, when I go to this file, "hello.php", it doesn't get parsed. In Firefox, I get the whole source like above, displayed back on the page. In IE, I just get an empty page, though the page title does get changed to "PHP Test."

I can't figure oput what the problem is. Can anyone help?

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 July 2006 - 04:01 AM

Apache needs to be instructed to parse php. Below are common additions to Apache's configuration file:

LoadModule php5_module	modules/libphp5.so # Windows uses a dll.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Imark

Imark
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 July 2006 - 04:11 AM

What exactly do I have to do?

Which files in the Apache directory do I need to edit, and how should I edit them?

The package I installed should have had everything pre-configured -- it would be very strange if I had to instruct Apache to parse PHP.

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 July 2006 - 04:15 AM

I can't speak for packages--I don't use them. You may want to try reading its documentation or contacting someone associated with it. The manual way, if everything was installed properly, is to edit httpd.conf in the conf directory of Apache. You can use notepad to add these directives to it, then restart the server.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 Imark

Imark
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 July 2006 - 04:28 AM

httpd.conf is a binary file -- you cant just paste a few lines into it.

Is it easy to set everything up, if I'd be installing it manually?

And will it be easy to configure the same Apache server to use with Java?

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 July 2006 - 04:31 AM

Every httpd.conf I've worked with has been ASCII, and this is how they are delivered with Apache. A basic setup is fairly easy; you can find a slew of tutorials on the web. I assume you're on Windows? I've never used Java with Apache--I think this is called Apache Tomcat.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 Imark

Imark
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 July 2006 - 04:39 AM

I am on Windows. My httpd.conf is a binary file, and I can't even touch it.

I heard the name Tomcat, and I'm wondering if it's an Apache version that can be used both for PHP and Java? [/wild guess]

#8 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 July 2006 - 04:47 AM

I haven't done as many Windows installs as Unix, but they have been very easy. You might want to try it. As for the configuration file, perhaps your package did something to it. You can research Tomcat further at http://www.apache.org.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#9 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 July 2006 - 01:45 PM

How are you invoking the script? Are you double clicking the file or typing URL http://localhost/hello.php

If you're double clicking, that is your problem. PHP needs to be processed by the web server, when you double click, the script is interpreted by the browser directly and the server is not invoked.

Ken

#10 Imark

Imark
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 19 July 2006 - 10:59 PM

Thanks, guys.

I figured out what the problem was. It has nothing to do with php or apache, and it's embarassing :-[

My Windows, by default, didn't show the extentions for known file types. When I saved my hello.php in Notepad, Windows saved it as hello.php.txt, without letting me know. That's how Apache didn't get to parse it -- because it didn't see it as a PHP file.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users