test.php not displayed correctly- just the text is displayed

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
ssquare
Forum Newbie
Posts: 5
Joined: Tue Oct 17, 2006 12:27 am

test.php not displayed correctly- just the text is displayed

Post by ssquare »

I am a new user of php/apache and was trying to set it up on my box. Despite my repeated attempt, I can't get apache to recognize the php code correctly; apache treats it as a text. When I do view source, I see the php text. I have added these three files in my httpd.conf

LoadModule php5_module "D:/Apps/PHP/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "D:/Apps/PHP"

I have verified to make sure that the path are abolutely correct. Also php.ini files does exist in d:/apps/PHP directory.

I am using 2.0.59 version of apache and PHP 5.1.6 version. Any help would be highly appreciated. (I have also tried to set the doc_path in php.ini to to the ../htdocs directory but that does not do any good.

I know the apache is working fine since I can pull up the index.html just fine. The problem is making apache recognize the php file

Thanks
SS
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Did you forget to restart Apache after making the changes to it's .conf file?
ssquare
Forum Newbie
Posts: 5
Joined: Tue Oct 17, 2006 12:27 am

Post by ssquare »

I have done that multiple times. Is there any log files I can look at on the php side? I have checked apache logs and everything seems fine.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Startup errors are sent to Apache's error log.

Where in the httpd.conf did you add those lines?
ssquare
Forum Newbie
Posts: 5
Joined: Tue Oct 17, 2006 12:27 am

Post by ssquare »

Right after loadmodule section
LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule ssl_module modules/mod_ssl.so

#Added by me
LoadModule php5_module "D:/Apps/PHP/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "D:/Apps/PHP"


I have tried to add addtype at the bottom (with two other add types), and when that did not work, I tried this approach.

BTW, FYI - I had a virus infecting my computer a month back. I have cleaned that up using avast. But I wonder could it be some kind of lingering effect of that virus.

Another note, I do see php configured correctly from the error.log file (in apache directory)
[Tue Oct 17 08:57:33 2006] [notice] Apache/2.0.59 (Win32) PHP/5.1.6 configured -- resuming normal operations
[Tue Oct 17 08:57:33 2006] [notice] Server built: Jul 27 2006 15:55:03
[Tue Oct 17 08:57:33 2006] [notice] Parent: Created child process 520
[Tue Oct 17 08:57:33 2006] [notice] Child 520: Child process is running
[Tue Oct 17 08:57:33 2006] [notice] Child 520: Acquired the start mutex.
[Tue Oct 17 08:57:33 2006] [notice] Child 520: Starting 250 worker threads.
[Tue Oct 17 09:07:23 2006] [notice] Parent: Received restart signal -- Restarting the server.
[Tue Oct 17 09:07:23 2006] [notice] Child 520: Exit event signaled. Child process is ending.

Not sure what is it that apache is reporting as an error in these messages.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your snips would suggest PHP is loaded correctly. Hmm. How are you accessing the test php script? Is the "engine" directive 1/true/on in php.ini? Is there an .htaccess file in the parentage of the location where your .php file is that has an engine 0/false/off directive in it?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This is what my Apache configration looks like. I am on WinXP, Apache 2.0 and PHP5.1.6. Note: This is at the end of the conf file.

Code: Select all

# Added by me to allow for PHP5 use
# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"
ssquare
Forum Newbie
Posts: 5
Joined: Tue Oct 17, 2006 12:27 am

Post by ssquare »

The way I am accessing the php script is 1. Create a test.php file in htdocs directory. 2. put the text string <?phpinfo();?> in the test.php 3. Go to browser and type in localhost/test.php

The engine directive is on (I basically took the php.ini.recommended, and copied it as php.ini)

The apache directory does not have any .htaccess in it. Is there a way to see if the php is installed correctly (all I did to install php was unzip the downloaded file. are there other steps, like updating the path to get this install correctly)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Short tags is off by default I believe in 5.1.6. <?php phpinfo(); ?> may produce the desired results.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Just another notch on the bedpost of 'Short PHP tags are evil'.
ssquare
Forum Newbie
Posts: 5
Joined: Tue Oct 17, 2006 12:27 am

Post by ssquare »

That did the trick. Thanks a bunch for your responses.

One final questions - Though I don't quite understand yet what is short tags, but is it advisable to stay away from it, and if I have to turn it on (to make third party software to work), what is the best way to do it?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Short tag:
<?

Good tag:
<?php

Always use regular opening PHP tags (<?php) when coding. It makes it compatible with future versions of PHP.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

ssquare wrote:and if I have to turn it on (to make third party software to work), what is the best way to do it?
There's a short_tags directive in php.ini... it can't be done inside the PHP script.
Post Reply