简体   繁体   English

为什么 MAMP 不显示错误?

[英]Why MAMP doesn't display errors?

OK this is getting very frustrating.好的,这变得非常令人沮丧。 MAMP used to display errors but then stopped. MAMP 曾经显示错误,但后来停止了。 I decided to do a fresh install of it as I couldn't figure it out.我决定重新安装它,因为我无法弄清楚。 I check my PHP version, running 5.4.4 and go to that folder and change the php.ini to this:我检查我的 PHP 版本,运行 5.4.4 并转到该文件夹​​并将 php.ini 更改为:

error_reporting  =  E_ALL
display_errors = On

Still no errors showing.仍然没有错误显示。 I go through all the folders and change all php.ini files, just in case.我浏览了所有文件夹并更改了所有 php.ini 文件,以防万一。 Nothing.没有什么。 I fix the forced error and dump out phpinfo() , check the error section and display_errors is Off.我修复了强制错误并转储了phpinfo() ,检查错误部分并且 display_errors 是关闭的。 What the hell.我勒个去。

I place error_reporting(E_ALL); ini_set('display_errors', 'on');我放置error_reporting(E_ALL); ini_set('display_errors', 'on'); error_reporting(E_ALL); ini_set('display_errors', 'on'); at the start of the PHP file and phpinfo() again.在 PHP 文件和phpinfo()的开头。 Local value is now On, master is still Off.本地值现在是 On,master 仍然是 Off。 Force a PHP error, and still get Server Error not PHP error.强制出现 PHP 错误,但仍然得到服务器错误而不是 PHP 错误。

Anybody have any insight?有人有任何见解吗? I have a bug somewhere in some code and cannot find it, would love for PHP to just tell me.我在某些代码的某处有一个错误并且找不到它,希望 PHP 告诉我。

MAMP sets up a few different php.ini files for the server, the client etc. Check in your phpinfo() which php.ini actually is read. MAMP 为服务器、客户端等设置了几个不同的php.ini文件。检查你的phpinfo()实际上读取了哪个php.ini Looks like you're editing the wrong one.看起来你编辑错了。

There are two php.ini files on MAMP. MAMP 上有两个php.ini文件。 You should change both php.ini files.您应该更改两个php.ini文件。

  1. Applications/MAMP/bin/php/'php version you are using(php5.5.10)'/conf/php.ini
  2. Applications/MAMP/conf/php/'php version you are using(php5.5.10)'/conf/php.ini

Then change:然后改变:

display_errors = Off 

to:到:

display_errors = On

If you're using MAMP PRO, you've to enable Error handling (PHP) in the UI interface which should contain at least two the main options: 'Display startup errors' and set output 'To: Display'.如果您使用的是 MAMP PRO,则必须在 UI 界面中启用错误处理 (PHP),该界面应至少包含两个主要选项:“显示启动错误”和设置输出“至:显示”。

Display startup errors option is equivalent to display_startup_errors (in PHP) and To: Display to display_errors . Display startup errors选项等效于display_startup_errors (在 PHP 中)和To: Display to display_errors

See below:见下文:

MAMP PRO - 错误处理

Change the setting in your php.ini file.更改php.ini文件中的设置。 The file is located in MAMP > conf > php5 > php.ini该文件位于MAMP > conf > php5 > php.ini

Look for display_errors = Off and change to display_errors = On查找display_errors = Off并更改为display_errors = On

After that you need to restart your Apache and MySQL servers for the change to take effect.之后,您需要重新启动 Apache 和 MySQL 服务器以使更改生效。

MAMP PRO 用户可以访问 UI 中的 PHP 选项卡并确保 Log Errors: to screen 被选中: screencast

Here's a 2018 update to this problem.这是此问题的 2018 年更新。 First, I'm having the same trouble and found this thread.首先,我遇到了同样的问题并找到了这个线程。 I used phpinfo() and found yet another location of a php.ini file.我使用了 phpinfo() 并找到了 php.ini 文件的另一个位置。 Here are the paths (I work on a Mac):以下是路径(我在 Mac 上工作):

/Applications/MAMP/bin/php/[php version]/conf/php.ini

/Applications/MAMP/conf/php/[php version]/php.ini

and ...和 ...

/Library/Application Support/appsolute/MAMP PRO/conf/php.ini

The phpinfo() page lists two sources for the php.ini: phpinfo() 页面列出了 php.ini 的两个来源:

  • Configuration File (php.ini) Path配置文件(php.ini)路径
    /Applications/MAMP/bin/php/[php version]/conf /Applications/MAMP/bin/php/[php 版本]/conf
  • Loaded Configuration File /Library/Application Support/appsolute/MAMP PRO/conf/php.ini加载的配置文件/Library/Application Support/appsolute/MAMP PRO/conf/php.ini

I ended up changing all three, adding error_reporting(E_ALL) to some pages, restarting the server (even rebooted the machine) and still cant get it to display any error messages.我最终更改了所有三个,将error_reporting(E_ALL)添加到某些页面,重新启动服务器(甚至重新启动机器),但仍然无法显示任何错误消息。

I'm not sure where to go from here.我不知道从这里去哪里。 Any ideas?有任何想法吗?

**** ---------------------------------------------- **** 2020 Edit **** ---------------------------------------------- **** The latest MAMP upgrade (v6) has changed the main web host directory. **** ---------------------------------------------- **** 2020 编辑 **** ---------------------------------------- ------ **** 最新的 MAMP 升级 (v6) 已更改主 Web 主机目录。 It's not in the Applications/MAMP/ directory.它不在 Applications/MAMP/ 目录中。 That's a good thing.这是好事。 But it required me to change where all my projects live.但它要求我改变我所有项目的所在地。 I had to reconfigure my IDE, Postman, Git, and some others.我不得不重新配置我的 IDE、Postman、Git 和其他一些。 So, I figured this would be a perfect time to move to Docker containers.所以,我认为这将是迁移到 Docker 容器的最佳时机。

Docker brings a whole new level of challenges but once I got familiar with it and deployed a few containers, it's been great. Docker 带来了全新的挑战,但是一旦我熟悉了它并部署了一些容器,它就很棒。 It feels faster when rendering in the browser and I am more confident that my projects will run as expected on the production server.在浏览器中渲染时感觉更快,我更有信心我的项目将在生产服务器上按预期运行。 Eventually our production servers will use containers, so it just makes sense for me.最终我们的生产服务器将使用容器,所以这对我来说很有意义。

If you are using MAMP version 3.2.2 then you only need to change one php.ini file:如果您使用的是 MAMP 3.2.2 版,那么您只需要更改一个 php.ini 文件:

Mac: Applications/MAMP/conf/'(php7.0.9)'/php.ini Mac: Applications/MAMP/conf/'(php7.0.9)'/php.ini

Windows: C:\\MAMP\\conf\\PHP Version you use'(php7.0.9)'\\php.ini Windows: C:\\MAMP\\conf\\PHP Version you use'(php7.0.9)'\\php.ini

I know this is an old post but MAMP keeps changing their configuration of the files so I hope this helps.我知道这是一篇旧帖子,但 MAMP 一直在更改他们的文件配置,所以我希望这会有所帮助。

For newer versions of MAMP, the config file is stored in Appliations/MAMP/bin/php/[php version]/conf .对于较新版本的 MAMP,配置文件存储在Appliations/MAMP/bin/php/[php version]/conf

Andrew Nagy pointed me in the right direction with his answer, but it wasn't quite correct for my installation of MAMP. Andrew Nagy 用他的回答为我指明了正确的方向,但对于我安装的 MAMP 来说并不完全正确。 Why they're different, I can't tell, but here we are.为什么它们不同,我不知道,但我们在这里。

If anyone is stuck, the easiest thing to do is to just <?php echo phpinfo(); ?>如果有人卡住了,最简单的方法就是<?php echo phpinfo(); ?> <?php echo phpinfo(); ?> in the index file of the application and look for the loaded php.ini directory. <?php echo phpinfo(); ?>在应用程序的索引文件中查找加载的php.ini目录。

Also there is a template saved in MAMP of the php.ini .还有一个模板保存在php.ini MAMP 中。 Go to File > Edit Template > PHP > Your Version .转到“ File > Edit Template > PHP > Your Version

在 MAMP 3.2.0 和 PHP 7 上,您需要定位php.ini-production并将值更改为Production Value = On

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM