Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...