apache MAMP 配置帮助,显示 PHP 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2297618/
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-09-13 18:48:24  来源:igfitidea点击:

MAMP Config help, display PHP errors

phpapachemamp

提问by Jonathan Musso

I am running the latest version of MAMP on Snow Leopard.

我在雪豹上运行最新版本的 MAMP。

My php.ini file has been configured to display errors. display_errors = on. The phpinfo(); page displays the status of error reporting, it is on. I have restarted my web server several times.

我的 php.ini 文件已配置为显示错误。display_errors = 开。phpinfo(); 页面显示错误报告的状态,它是打开的。我已经多次重新启动我的网络服务器。

I've searched through Google, and I cannot find any similar problem. Everyone just says to do exactly what I have done, but it is not working. The pages will just remain blank, (with no reporting), if I intentionally place errors.

我已经通过谷歌搜索过,我找不到任何类似的问题。每个人都只是说按照我所做的去做,但它不起作用。如果我故意放置错误,页面将保持空白(没有报告)。

Any thoughts as to what the problem may be?

关于问题可能是什么的任何想法?

回答by Mikael Kessler

For any future posters who run into this issue...

对于任何遇到此问题的未来海报...

I was having the same issue and found that I was making changes to the wrong php.ini files. Run phpinfo and find the path to the active php.ini file to make sure you're editing the correct one.

我遇到了同样的问题,发现我正在对错误的 php.ini 文件进行更改。运行 phpinfo 并找到活动 php.ini 文件的路径,以确保您正在编辑正确的文件。

On my installation of mamp there were multiple instances of the /conf directory with php.ini files. The php.ini files I needed were located in the /bin/php/php[version#]/conf directory and not the MAMP/conf directory.

在我安装 mamp 时,/conf 目录中有多个实例,其中包含 php.ini 文件。我需要的 php.ini 文件位于 /bin/php/php[version#]/conf 目录中,而不是 MAMP/conf 目录中。

Exact path to the php.ini file I needed to edit:

我需要编辑的 php.ini 文件的确切路径:

Applications/MAMP/bin/php/php5.4.10/conf/php.ini

应用程序/MAMP/bin/php/php5.4.10/conf/php.ini

Change display_errors = Offto display_errors = On

更改display_errors = Offdisplay_errors = On

回答by Pascal MARTIN

In addition to the display_errorsdirective, which has to be set to On, you might have to configure error_reporting.

除了display_errors必须设置为 的指令外On,您可能还需要配置error_reporting

For instance, you can use this in your php.inifile :

例如,您可以在您的php.ini文件中使用它:

error_reporting = E_ALL


Another should, useful to test, might be to place this kind of portion of PHP code at the beginning of your script :


另一个对测试有用的应该是将这种 PHP 代码部分放在脚本的开头:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

This is useful when you don't have access to php.ini and/or just want to test quickly, without having to restart the webserver.

当您无法访问 php.ini 和/或只想快速测试而无需重新启动网络服务器时,这很有用。


As a sidenote, when it comes to displaying errors, the Xdebugextension is really great : when it's installed/enabled/configured, instead of just having an error message, you'll get the full stack-trace, which is much more useful ;-)


作为旁注,当涉及到显示错误时,Xdebug扩展真的很棒:当它被安装/启用/配置时,你会得到完整的堆栈跟踪,而不是只有一条错误消息,这更有用; -)

回答by hollsk

I recently experienced the same problem - in my case I had downloaded a client's Wordpress site from their live server that turned out to have been tampered with by malicious script insertion that was overriding the error reporting in order to escape detection.

我最近遇到了同样的问题 - 在我的情况下,我从他们的实时服务器下载了一个客户端的 Wordpress 站点,结果证明该站点已被恶意脚本插入篡改,该脚本插入覆盖错误报告以逃避检测。

A little late to help the OP(!), but perhaps of use to future searchers.

帮助 OP(!) 有点晚了,但也许对未来的搜索者有用。

回答by jhchen

There might have a .htaccess file in a directory that overrides the display_errors setting set in php.ini. From your post I assume you didn't explicitly add this but a few frameworks do this by default so might be added that way. Look for a line like this in your .htaccess file:

在覆盖 php.ini 中设置的 display_errors 设置的目录中可能有一个 .htaccess 文件。从您的帖子中,我假设您没有明确添加此内容,但默认情况下有一些框架会执行此操作,因此可能会以这种方式添加。在 .htaccess 文件中查找这样的行:

php_value display_errors 0

and change the value to 1.

并将值更改为 1。

回答by Eranda

If you have several php sdks with several versions, first make it sure you are editing correct php.ini file. If you were right add this two lines at the beginning of the code.

如果您有多个具有多个版本的 php sdks,请首先确保您正在编辑正确的 php.ini 文件。如果你是对的,在代码的开头添加这两行。

error_reporting(E_ALL);
ini_set('display_errors', 'On'); // or ini_set('display_errors', 1);

回答by Thanh Pham

Here's a twist to the same answer. I had the same issues, just copied and pasted the ini path from the php info page and still same problems...

这是同一个答案的一个转折。我遇到了同样的问题,只是从php信息页面复制并粘贴了ini路径,但仍然存在同样的问题......

turns out I made a syntax mistake when I edited my 'error_reporting' block in the php.ini.

原来我在 php.ini 中编辑“error_reporting”块时犯了一个语法错误。

I had E_NOTICE rather than ~E_NOTICE.

我有 E_NOTICE 而不是 ~E_NOTICE。

:(

:(

So mistakes can happen in the php.ini if you were editing it and totally forgot you edited something.

因此,如果您正在编辑 php.ini 并完全忘记您编辑了某些内容,则可能会在 php.ini 中发生错误。