Forum Moderators: phranque
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.
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
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?
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
[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.
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.
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]
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.
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 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
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.
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.