PHP 文件由浏览器下载,而不是由本地开发服务器 (MAMP) 处理 [英] PHP files are downloaded by browser instead of processed by local dev server (MAMP)

查看:25
本文介绍了PHP 文件由浏览器下载,而不是由本地开发服务器 (MAMP) 处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切都很顺利,直到我将 AddHandler application/x-httpd-php5s .php 添加到本地服务器文档根目录中的 .htaccess 文件中(我经常根据我所在的站点更改该文件)工作).因为我在访问 http://localhost:8888 时这样做了,所以我的浏览器只下载了 index.php 并且没有在所有,只是原始代码.现在我从 .htaccess 文件中删除了该行,但我仍然遇到这个问题.

我发现,如果我为 127.0.0.1 的主机文件添加一个替代条目,则新条目的行为就像以前的localhost".但是,如果我将上面的行添加到我的 .htaccess 中,它也会淘汰那个新主机.我尝试重新安装 MAMP 并清除其缓存和我能找到的所有临时文件.我浏览了 Apache 的 httpd.conf 文件,但无济于事.

所以,要清楚:http://localhost:8888 遇到了上述问题.如果我为 127.0.0.1 在我的主机文件中添加一个新条目,例如goomba"并且上面的行不在根 .htaccess 中(并且从来没有用于该主机/别名/任何内容),那么我可以访问 http://goomba:8888 就好了.但是,如果我确实将该行添加到 .htaccess 中,那么我必须在我的主机文件中添加另一个条目以解决它即使我从 .htaccess 文件中删除了该行.

我可以使用不同的 127.0.0.1 别名(主机?那叫什么?)但让我烦恼的是这仍然是坏的.

需要说明的是,我使用的是 Mac OS Leopard(但我没有使用内置的 Apache 设置,而是使用 MAMP).

解决方案

您在处理程序应在的位置应用 mimetype(请参阅 有关处理程序的文档)

试试这个:

AddType 应用程序/x-httpd-php5 .php

正如您已经指出缓存模块已加载,您可以阅读 cachinghtcacheclean(清除磁盘缓存).您还可以临时使用 CacheDisable 指令.您还可以尝试的另一件事是重命名您请求的文件(例如 index.php -> index.bak),在浏览器中再次请求该文件(现在应该是 404),然后还原并重试.

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

解决方案

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.

这篇关于PHP 文件由浏览器下载,而不是由本地开发服务器 (MAMP) 处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆