php Apache下载php文件而不是执行脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8083599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:55:57  来源:igfitidea点击:

Apache downloads php files instead of executing script

phpapache

提问by Pardoner

I just set up a local web server on a new Mac running 10.6 (Apache2 / PHP / Mysql). Everything seems to be working fine except when I navigate to SOME(not most) pages Apache downloads php files instead of executing them.

我刚刚在运行 10.6 (Apache2/PHP/Mysql) 的新 Mac 上设置了一个本地 Web 服务器。一切似乎都运行良好,除非我导航到某些(不是大多数)页面时 Apache 下载 php 文件而不是执行它们。

I thought this might have something to do with the time it takes php to execute the script so I increased my "max_execution_time" but it didn't help.

我认为这可能与 php 执行脚本所需的时间有关,所以我增加了“max_execution_time”,但没有帮助。

I wish I could give more details but the error logs don't output anything so I really have no idea why this is happening. One thing that might be of significance is that only pages that don't query the database seem to work every time.

我希望我能提供更多详细信息,但错误日志不输出任何内容,所以我真的不知道为什么会发生这种情况。可能很重要的一件事是,只有不查询数据库的页面似乎每次都在工作。

UPDATE:

更新:

Just discovered something strange that might give more insite into the problem. If I type the following URLs:

刚刚发现了一些奇怪的东西,可能会给问题带来更多的现场。如果我输入以下网址:

localhost/index.php // the home page is served up correctly

localhost/index.php // 主页服务正确

localhost/index.php?page=1 // the home page is served up correctly

localhost/index.php?page=1 // 主页服务正确

localhost/index.php?page=home // ERROR: index.php is downloaded !!!!!!!!!!

localhost/index.php?page=home // 错误:index.php 已下载 !!!!!!!!!!!!

localhost/index.php?page=contact // the contact page is served up correctly

localhost/index.php?page=contact // 联系页面正确提供

localhost/index.php?page=blog // ERROR: index.php is downloaded

localhost/index.php?page=blog // 错误:index.php 被下载

localhost/index.php?page=10 // the blog page is served up correctly

localhost/index.php?page=10 // 博客页面正确服务

回答by JWarner

Uncommenting the following line in /etc/apache2/httpd.conf fixed the problem for me:

取消注释 /etc/apache2/httpd.conf 中的以下行为我解决了问题:

LoadModule php5_module libexec/apache2/libphp5.so

回答by 472084

You could try adding this to your conf or htaccess:

您可以尝试将其添加到您的 conf 或 htaccess 中:

AddType application/x-httpd-php .php

回答by Todd Just

I know that this was asked a long time ago, but I just encountered this problem so I thought I'd post what the cause was for me.

我知道很久以前就有人问过这个问题,但我刚刚遇到了这个问题,所以我想我会发布原因是什么。

Make sure that you don't have...

确保你没有...

AddHandler application/x-httpd-php5 .php

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

...in BOTH your .htaccess file and your httpd.conf file. Check your .htaccess file, comment it out, restart Apache, and try again. That is most likely your problem since Apache renders php for some sites but not others. It has to be at the directory level, which would point to a .htaccess file setting.

...在您的 .htaccess 文件和 httpd.conf 文件中。检查您的 .htaccess 文件,将其注释掉,重新启动 Apache,然后重试。这很可能是您的问题,因为 Apache 为某些站点呈现 php 而不是其他站点。它必须在目录级别,这将指向 .htaccess 文件设置。

回答by Ned

I stumbled upon this problem after upgrading php to 5.5 and reinstalling apache.

在将 php 升级到 5.5 并重新安装 apache 后,我偶然发现了这个问题。

Finally,this fixed it, in case someone else needs it.

最后,这修复了它,以防其他人需要它。

apt-get install libapache2-mod-php5

apt-get install libapache2-mod-php5

(here's the answer)

这是答案