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

Viewed 57902

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).

12 Answers

You are applying a mimetype where a handler should be (see documentation on handlers)

Try this instead:

AddType application/x-httpd-php5 .php

EDIT: As you have indicated caching modules are loaded, you could read up on caching and htcacheclean (to clear the disk cache). You can also temporarily use the CacheDisable directive. One other thing that you could also try is to rename the file that you have requested (e.g. index.php -> index.bak), request the file again in the browser (should now 404), then revert and try again.

Just note, make sure you don't have a htaccess file from your live environment accidentally downloaded with other files. Additionally, make sure you match your PHP version when editing htaccess. Wrong version cause same issue-wrong settings.

Here is an example for running PHP7:

application/x-httpd-ea-php71 .php .php7 .phtml

I hope this info can help - it happened to me 8 years after ticket is created :)

Perhaps you want application/x-httpd-php5 instead of application/x-httpd-php5s? (Note the lack of an s at the end.)

If someone has again this kind of issue, do something most important firstly. I mean, use private navigation (without cache). I wasted my time because of this.

GLHF

I had the same issue and it was because inside this folder you have .htaccess file hidden with some custom code, for me was because I copy from my running website server. Try to rename the file and you will see your project. Then customise the file in your needs.

First check if your apache server is running. Start->Run->cmd and then execute command:

netstat -abn

Lookup the result for line like this:

TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING 600 [apache.exe]

If you cant find anything listening on port 8888 ( no 0.0.0.0:8888 line) then your apache is failing to start. To find out why it cant start you should find apache log directory and examine the error.log (may be you have updated your php resently?). If you find 0.0.0.0:80 listening line but some other software is listening there (do you have IIS running?) then you should remove / reconfigure that softure to free port 80. If you have apache listening on port 80 but still cant open your site and you cant figure out what is causing the problem via examining apache log files then it my be database problem. Check if your mysql is running and listening using same command but you should be looking for

TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING [mysqld-nt.exe]

If you cant find such line then your mysql server is not running - check mysql log files for errors. If both servers are running and you cant get any output in your browser then check your firewall and antivirus - they may block your requests. Hope this helps ;)

Just remove the comment

<IfDefine PHP>
   LoadModule php_module        modules/libphp.so
</IfDefine>

in etc/extra/httpd-xampp.conf

In my case after cloning a repo and trying to set the project up i hade to run composer update to install the all dependencies and then it open the page instead of downloading the file

Related