Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 09-17-2006, 05:33 PM   #1
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
Apache2 is serving PHP source files unless called without the extension

I'm having an odd problem with PHP.

I have got a partial and ugly work-around using mod_rewrite, but I'm stumped as to how to fix the problem.

I have upgraded my Debian box to apache2 with PHP using apt-get. Before the upgrade, I had gallery (a PHP program) working well.

The main page in main.php, but if I browse to that location then I get the option to download the source for that page.

However, if I leave out the ".php" extension, then it runs the PHP script and outputs the correct HTML except that the links now have a /main/ inserted into them, which stops some things from working.

I have cleared my browser's cache several times (and even tried it with a different browser). I can't see anything different with the PHP code between the previous and current versions, except that things are laid out differently (mods-enabled/php4.{load,conf} instead of conf.d/php4.conf).

Does anyone know of any apache setting that could cause this sort of behavior?
Old 09-17-2006, 08:49 PM   #2
Registered: Feb 2006
Distribution: FC
Posts: 86

Rep: Reputation: 15
Do you have a php.conf file to tell Apache what to do with the .php extension? On my system using Apache 2 and php 5 I have a file call php.conf in /etc/httpd/conf.d/ that looks like this:

# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.

LoadModule php5_module modules/

# Cause the PHP interpreter to handle files with a .php extension.
AddHandler php5-script .php
AddType text/html .php

# Add index.php to the list of files that will be served as directory
# indexes.
DirectoryIndex index.php

# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#AddType application/x-httpd-php-source .phps
If you don't have it then add it, then restart your server. As root type in:

/sbin/service httpd restart

Don't know if that's what your problem is... but that's my attempt.
Old 09-18-2006, 01:55 AM   #3
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Original Poster
Rep: Reputation: 76
My php4.conf is:[code]<IfModule mod_php4.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps

My php4.load is:
LoadModule php4_module /usr/lib/apache2/modules/
These are both in /etc/apache2/mods_enabled

After reading your post, I've tried setting AddHandler, but it didn't seem to have any effect.
Old 12-08-2006, 06:17 AM   #4
LQ Newbie
Registered: Dec 2006
Posts: 1

Rep: Reputation: 0
I had a simular problem this was resolve by going to the apache2.conf folder and looking at the following line
# AddType text/plain .html .htm .shtml .phtml .phtm .pl .py .cgi .php

you need to make sure it is commented out as shown above (the order of the extentions maybe different to your .conf so search on AddType in your file)

not sure how mine was uncommented but it was the cause of my problem


apache2, debiansoftware, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2.0.52, t1lib-5.0.2, php-apache2-5.0.2 wizard7423 Slackware 2 04-04-2011 08:09 PM
Apache2 won't load index.php files foucault Linux - Software 11 03-20-2010 09:08 PM
Have installed PHP for Apache2 but source code showing Tomo3000 SUSE / openSUSE 4 08-04-2005 07:14 PM
Apache2 running but not serving any page Kerion Linux - Newbie 4 07-28-2004 05:16 PM
RedHat8->Apache2->PHP4->Extension (_Unwind_Resume) problem TimeSaver Programming 0 03-19-2003 01:07 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration