Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP files are downloaded by browser instead of processed by local dev server (MAMP)

Everything was going great until I added AddHandler application/x-httpd-php5s .php to the .htaccess file in my local server's document root (which I change frequently depending on the site I'm working with). Since I did that when I visit http://localhost:8888 my browser just downloads the index.php and it's not processed at all, just the raw code. Now I removed that line from the .htaccess file but I'm still having this problem.

I've found that if I add an alternative entry to my hosts file for 127.0.0.1 the new entry behaves like 'localhost' used to. But if I add the line above to my .htaccess it knocks out that new host as well. I've tried reinstalling MAMP and clearing its caches and all the temporary files I could find. I surfed through Apache's httpd.conf file all to no avail.

So, to be clear: http://localhost:8888 is experiencing the above problem. If I add a new entry to my hosts file for 127.0.0.1, say 'goomba' and the above line is not in the root .htaccess (and has never been for that host/alias/whatever) then I can access http://goomba:8888 just fine. But if I do add that line to the .htaccess then I have to add yet another entry to my hosts file to get around it even if I remove that line from the the .htaccess file.

I'm fine with using a different 127.0.0.1 alias (host? what is that called?) but it's bugging me that this is still broken.

Just to be clear, I'm on Mac OS Leopard (but I'm not using the built in Apache setup, but MAMP).

like image 608
9 revs Avatar asked Feb 23 '10 08:02

9 revs


People also ask

Why is my php file downloading instead of running?

This is normally due to an improper handler code. In the . htaccess file, you will want to ensure the handler code matches your version of php. If it does not, the php files may try to download instead of process.

Where does Apache save php files?

php. This component saves the uploaded file to a folder named upload in the Apache server's htdocs directory.

Does Mamp install php?

MAMP is essentially a program you download that makes your computer into a server – with the ability to run PHP and mySQL. Once installed, MAMP will automatically make files under a certain folder (your choice) accessible like a website for you.


1 Answers

I've had a similar issue a couple times and renaming the file did not work for me. With OS X Lion I found the right configuration is this:

<IfModule php5_module>
    AddType application/x-httpd-php .php
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
    AddType application/x-httpd-php-source .phps
    <IfModule dir_module>
        DirectoryIndex index.php index.html
    </IfModule>
</IfModule>

The magic that made it work for me is the SetHandler application/x-httpd-php part.

Of course edit the <IfModule php5_module> to your php version.

like image 168
Matt Grannary Avatar answered Sep 25 '22 07:09

Matt Grannary