homepage Welcome to WebmasterWorld Guest from 54.242.126.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
browser asking me to download php files
banglo

5+ Year Member



 
Msg#: 3418477 posted 1:43 am on Aug 10, 2007 (gmt 0)

Hi,

I've been using MAMP to develop a website on my laptop. I've had no trouble in the last couple of months till today. I don't know what I could have done to cause the error but whenever I try to access any php file through any browser, I am asked whether I want to download the file. Seems like Apache is not interpreting the php file. Like I mentioned, I have not changed any MAMP/Apache settings so I don't know what could have caused this behavior. I would much appreciate your help in this. Thank you.

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3418477 posted 3:01 am on Aug 10, 2007 (gmt 0)

Look at all instances of AddHandler and AddType directives in your httpd.conf, conf.d, and .htaccess files and compare them to your recent backups.

You may also wish to check the MIME-type currently being sent to the browser by using the "Live HTTP Headers" extension for Firefox and other Mozilla-based browsers.

Jim

banglo

5+ Year Member



 
Msg#: 3418477 posted 3:42 am on Aug 10, 2007 (gmt 0)

Hi Jim

Thanks for responding. I hope you can help me this.

The problem is occuring in all browsers, IE, Opera, Safari and Firefox. I don't have a backup copy of the files you mentioned so I could not diff them. I did reinstall MAMP on my laptop so I have fresh versions of the files. But I still see the same behavior.
This is what I get back from Live HTTP Headers before I am asked to download the php file:

[localhost:8888...]

GET /ubtest/test.php HTTP/1.1

Host: localhost:8888

User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Cookie: evo_style=Variation

If-Modified-Since: Fri, 10 Aug 2007 01:22:16 GMT

If-None-Match: "fb92d-14d-34950200"

HTTP/1.x 304 Not Modified

Date: Fri, 10 Aug 2007 03:25:26 GMT

Server: Apache/2.0.59 (Unix) PHP/5.2.1 DAV/2 mod_ssl/2.0.59 OpenSSL/0.9.7l

Connection: Keep-Alive

Keep-Alive: timeout=15, max=100

Etag: "fb92d-14d-34950200"

Do you have any other suggestions?

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3418477 posted 4:02 am on Aug 10, 2007 (gmt 0)

That HTTP Header report wasn't useful, since the server returned a 304-Not Modified response (because you didn't flush your browser cache before doing the test), so the 'page' was served from the browser cache instead of from your server.

If you've got a fresh install and it still doesn't work, then I'd recommend going to wherever you got this MAMP package and asking about the problem in their forums.

If you want to do a "manual fix," then perhaps some of these threads [google.com] --mostly from our PHP forum-- will be of use.

The basis of your problem is this: Your Apache server is not (or no longer) configured to execute PHP files instead of sending them to the client. The theoretically-correct way to tell Apache to execute a script is to use the AddHandler directive. However, due to a kludge in the way PHP was first implemented, the seemingly-nonsensical application of the AddType directive is sometimes required. As I understand it, whether you need to use AddHandler or AddType depends on whether your PHP is installed as a module or as CGI.

Jim

banglo

5+ Year Member



 
Msg#: 3418477 posted 4:17 am on Aug 10, 2007 (gmt 0)

I've tried posting on the MAMP forum, but to no avail. Here's some data from LiveHTTPHeader after I've cleared the cache:

[localhost:8888...]

GET /ubtest/test.php HTTP/1.1

Host: localhost:8888

User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Cookie: evo_style=Variation

HTTP/1.x 200 OK

Date: Fri, 10 Aug 2007 04:06:14 GMT

Server: Apache/2.0.59 (Unix) PHP/5.2.1 DAV/2 mod_ssl/2.0.59 OpenSSL/0.9.7l

Last-Modified: Fri, 10 Aug 2007 01:22:16 GMT

Etag: "fb92d-14d-34950200"

Accept-Ranges: bytes

Content-Length: 333

Keep-Alive: timeout=15, max=100

Connection: Keep-Alive

Content-Type: application/x-httpd-php

I agree with you. It definitely does seem like Apache is not compiling the php files as it should be. I'll take a look at the threads you mentioned. Here's the AddHandler,AddType blurb from Apache's httpd.conf:

#AddHandler cgi-script .cgi
#AddHandler send-as-is asis
#AddHandler imap-file map
AddHandler type-map var

AddType application/x-httpd-php .php .phtml
#AddType application/x-tar .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
#AddType text/html .shtml

Definitely let me know if you can think of what else could be wrong. Thank you.

SteveWh

5+ Year Member



 
Msg#: 3418477 posted 9:30 am on Aug 10, 2007 (gmt 0)

Instead of this line:

AddType application/x-httpd-php .php .phtml

Try substituting one of these, which do the same thing depending on your setup and configuration:

AddHandler application/x-httpd-php .php .phtml
AddHandler x-httpd-php .php .phtml

If your files aren't .php or .phtml, add the extension(s) you're using to the lines.

banglo

5+ Year Member



 
Msg#: 3418477 posted 9:04 pm on Aug 10, 2007 (gmt 0)

Hi Steve,

This is the last line of the output from Live HTTP Headers when I try to access a php file from my webserver:

Content-Type: application/x-httpd-php

But when I access any php page from any server on the web, this is the last line:

Content-Type: text/html

Could that be the issue?

SteveWh

5+ Year Member



 
Msg#: 3418477 posted 1:45 am on Aug 11, 2007 (gmt 0)

That's very interesting because by the time the file gets to your browser, it is an HTML file, not a php file. Only Apache is responsible for "caring" that it's PHP.

Try this in your php.ini file, and then try again each of the various AddType and Add Handler lines you've been trying:

expose_php = Off

If you keep getting the download prompt, try downloading the file. If it has PHP code in it, then the problem is that Apache is failing to pass the file to the PHP handler. If it has no PHP code, then Apache and PHP are doing their jobs, but your browser is misinterpreting the MIME type, if any, being sent.

Also, I've heard that Mac has different line ends from other operating systems. Is it possible you copied and pasted code or for some other reason your php.ini or httpd.conf files now have lines in them for which the Mac is somehow misinterpreting line ends; maybe merging lines that should be separate into one line, with one being ignored?

Edit: If you have both httpd.conf and .htaccess, make sure you don't have .htaccess code that overrides the httpd.conf settings.

[edited by: SteveWh at 1:49 am (utc) on Aug. 11, 2007]

banglo

5+ Year Member



 
Msg#: 3418477 posted 5:34 pm on Aug 11, 2007 (gmt 0)

Hi Steve,

Thanks for your help so far. I don't have a .htacess file So I turned expose_php off and here's what I get for respective add settings.

So I've tried the following values in httpd.conf:

#AddType application/x-httpd-php .php .phtml
#AddHandler application/x-httpd-php .php .phtml
#AddType text/html .php .phtml

When I use "AddType application/x-httpd-php .php .phtml",
I am prompted to download the file, and last line in the header is:

Content-Type: application/x-httpd-php

When I use "AddHandler application/x-httpd-php .php .phtml" or "AddType text/html .php .phtml", the browser displays php code (so just the literal content of the php file), and the last line in the header is:

Content-Type: text/plain

And to answer your question, I don't think it's the line ends in the document because after I reinstalled the entire server package (without changing any config files), I was still asked to download php files.

It does definitely seem like Apache does not know to interpret php files. The following line loads php5 on Apache I think:

LoadModule php5_module modules/libphp5.so

When expose_php was on, the php version was displayed in live HTTP Headers so php must be running on the server. Do you have any other ideas? Thanks again for helping me troubleshoot this issue.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3418477 posted 6:28 pm on Aug 11, 2007 (gmt 0)

Take a look at the Apache AddHandler directive documentation. That is the only "solid ground" in this whole scenario. As I stated, "hooking up" PHP to Apache has always been somewhat of a kludge, and that's what you're fighting.

You're also fighting "institutionalized" confusion between the very-different functions of AddType (which defines the MIME-type header to be returned with content to the client), and AddHandler, which tells the server how to handle each filetype in the server's filespace.

The examples posted above demonstrate this "institutionalized" confusion; Although the use "AddHandler application/x-httpd-php .php" to declare a MIME-type as a content-handler is glaringly nonsensical, the fact is that it will work on some servers.

In contrast, the "classical" AddHandler solution would call for
AddHandler server-parsed .php
-or-
AddHandler php-script .php

Rather than trying to define a MIME-type as a server content-handling method, these correctly declare that files of type ".php" should be parsed for scripted programming instead of being sent as literal text to the client.

Jim

banglo

5+ Year Member



 
Msg#: 3418477 posted 9:38 pm on Aug 11, 2007 (gmt 0)

Hi Jim,

These settings were preconfigured by the MAMP build. But before applying your change, I reinstalled the server package again. And independently tried

AddHandler php-script .php

and

AddHandler server-parsed .php

to httpd.conf

And I still have the browser asking me to download the file.

Is there any other way to check if Apache is making an association with php files and the php.so module? Thanks Jim.

SteveWh

5+ Year Member



 
Msg#: 3418477 posted 9:25 am on Aug 12, 2007 (gmt 0)

Have to admit I'm at a dead end on advice, but I went thru my (local WAMP) httpd.conf and copied all the lines that had anything to do with php:

LoadModule php5_module "c:/wamp/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/wamp/php"
AddHandler application/x-httpd-php .html .htm

[^Hm, that's odd; note that I've got both an AddType and AddHandler. Plus, the AddType line only tells it about .php. The AddHandler line tells it to parse .html and .htm AS IF they were .php.]

And in php.ini, some settings that look important:

; Enable the PHP scripting language engine under Apache.
engine = On

you don't need safe_mode on your local installation, and when it's enabled, it could conceivably prevent some scripts from running(?)

safe_mode = Off

Ensure every error is reported on the page when you preview it:

error_reporting = E_ALL E_STRICT
display_errors = On
display_startup_errors = On

In your first post you said: "I don't know what I could have done to cause the error". Before the errors began, did you install any new modules, edit php.ini or httpd.conf, reinstall MAMP, or otherwise modify any file in any way? The fact that it stopped working when it was working previously seems like it has got to be significant.

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3418477 posted 1:28 pm on Aug 13, 2007 (gmt 0)

I really can't offer much more here myself except for what has already been mentioned. From experience, I'll just note that you need to be careful with the tools used to edit conf files ...
Editing Apache httpd.conf in Dreamweaver crashes server [webmasterworld.com]
... and personally I never use anything but AddHandler with Apache >= 2.x. Details here: [webmasterworld.com...]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved