OS X 上的 PHP 调试 - 无望?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/80351/
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
PHP debugging on OS X - hopeless?
提问by Garrett Albright
I have tried:
我试过了:
- Xdebug and Eclipse. Eclipse launches a web browser, but the browser tries to access a non-existent file in Eclipse's .app bundle.
- Xdebug and NetBeans. It does a little bit better; a browser opens a page in /tmp which says "Launching. Please wait…" but nothing happens beyond that.
- Xdebug and debugclient, the CLI tool which comes with Xdebug. MacPorts (which I used to install PHP and Xdebug) doesn't seem to install this by itself, and when I try compiling it by hand, I get told "you have strange libedit". Installing libedit via MacPorts doesn't solve that.
- Zend's debugger (the precise name escapes me right now) and Eclipse. I can't recall what the problem was, as this was some time ago, but it didn't work.
- Xdebug 和 Eclipse。Eclipse 会启动 Web 浏览器,但浏览器会尝试访问 Eclipse 的 .app 包中不存在的文件。
- Xdebug 和 NetBeans。它做得好一点;浏览器在 /tmp 中打开一个页面,上面写着“正在启动。请稍候……”但除此之外什么也没有发生。
- Xdebug 和 debugclient,Xdebug 自带的 CLI 工具。MacPorts(我用来安装 PHP 和 Xdebug)似乎不会自己安装它,当我尝试手动编译它时,我被告知“你有奇怪的 libedit”。通过 MacPorts 安装 libedit 并不能解决这个问题。
- Zend 的调试器(确切的名称现在让我无法理解)和 Eclipse。我不记得是什么问题了,因为这是前一段时间,但它没有用。
With regards to Xdebug, at least, I'm fairly confident I've installed it correctly. It shows up with both a phpinfo() in a PHP file and a php -iin the CLI.
至少,关于 Xdebug,我相当有信心我已经正确安装了它。它在 PHP 文件和php -iCLI 中同时显示 phpinfo() 。
If anyone has managed to get PHP debugging working in some way or other on the Mac, I'd appreciate it if you could share with me how. Littering code with var_dump($foo);die();gets old quick. Bonus points if it can be done withoutusing some bloatware editor like Eclipse, or that expensive proprietary thing Zend wants to sell me.
如果有人设法在 Mac 上以某种方式使 PHP 调试工作,如果您能与我分享如何,我将不胜感激。乱扔垃圾的代码var_dump($foo);die();很快就会变老。如果不用像 Eclipse 这样的臃肿软件编辑器,或者 Zend 想卖给我的昂贵的专有东西就可以完成,那就加分。
My server is connecting to PHP via FastCGI, if that makes a diff.
我的服务器正在通过 FastCGI 连接到 PHP,如果这有区别的话。
采纳答案by Brian Benzinger
You may want to look into MacGDBp. It's new, free, and the UI looks great. It utilizes the Xdebug PHP extension as well. You can find instructions in the helpsection, which includes Xdebug configurations, and there's also a nice overview of the app from the guys at Particletree here: Silence The Echo with MacGDBp.
您可能需要查看MacGDBp。它是新的、免费的,而且用户界面看起来很棒。它也使用 Xdebug PHP 扩展。您可以在帮助部分找到说明,其中包括 Xdebug 配置,还有来自 Particletree 人员的应用程序概述:Silence The Echo with MacGDBp。
回答by Luke Dennis
Here's how I did it:
这是我如何做到的:
1 - Copy the latest version of xdebug.so from http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebuggingto /usr/libexec.
1 - 将最新版本的 xdebug.so 从http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging复制到 /usr/libexec。
2 - Add the following to the global php.ini:
2 - 将以下内容添加到全局 php.ini:
zend_extension="/usr/libexec/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
3 - Restart Apache and run MacGDBp.
3 - 重新启动 Apache 并运行MacGDBp。
回答by Henrique B.
Just wanted to update this thread to let you know there's a new app out here http://codebugapp.com/it's commercial, but it's Xdebug client for OSX
只是想更新这个线程,让你知道这里有一个新的应用程序http://codebugapp.com/它是商业的,但它是 OSX 的 Xdebug 客户端
回答by user15215
Been looking for php debugger for osx myself too. This one looks promising: http://www.turingart.com/phpdebugger_lan__en.htm
我自己也在寻找 osx 的 php 调试器。这个看起来很有希望:http: //www.turingart.com/phpdebugger_lan__en.htm
回答by Donskikh Andrei
There is a way how to do it using
有一种方法可以使用
- PhpStorm
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Php + Xdebug
- PhpStorm
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"PHP + Xdebug
1) Install php and debug
1)安装php并调试
brew install php70
brew install php70-xdebug
In PhpStorm - check Preferences => Language and Frameworks => PHP
Php language level: 7
Interpreter: PHP 7.0.8 + XDebug (or choose from [...])Check debug config: Preferences => Language and Frameworks => PHP => Debug => Xdebug section
All checkboxes should be checked and set Debug port to: 9001
在 PhpStorm 中 - 检查首选项 => 语言和框架 => PHP
Php 语言级别:7
解释器:PHP 7.0.8 + XDebug(或从 [...] 中选择)检查调试配置:首选项 => 语言和框架 => PHP => 调试 => Xdebug 部分
所有复选框都应选中并将调试端口设置为:9001
2) run server in your app's directory:
2)在您的应用程序目录中运行服务器:
php -S localhost:8080
3) Add localhost:8080 to PhpStorm Preferences => Language and Frameworks => PHP => Servers:
Name: Localhost:8080
Host: localhost
Port: 8080
Debugger: Xdebug
3) 将 localhost:8080 添加到 PhpStorm Preferences => Language and Frameworks => PHP => Servers:
Name: Localhost:8080
Host: localhost
Port: 8080
Debugger: Xdebug
4) Update php.ini:
Php => Interpreter => […] => Configuration file - Open in Editor
Add this section: (check zend_extention path through the cli)
4)更新php.ini:
Php => Interpreter => […] => Configuration file - Open in Editor
添加这部分:(通过cli检查zend_extention路径)
[Xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001 (same as in Debug preferences)
5) Add Debug Configuration: Run => Edit Configuration => add - Php Web Application
5)添加调试配置:运行=>编辑配置=>添加-Php Web应用程序
- Choose Localhost:8080 server
- 选择本地主机:8080服务器
6) Click Start Listening for Php Debug Connections
7) Set up breakpoints
7) Click on Debug (Green bug)
6) 点击 Start Listening for Php Debug Connections
7) 设置断点
7) 点击 Debug (Green bug)
回答by David
I use Komodo 5 --- debugging works wonderfully, not only with PHP, but also with Ruby and Python. I mostly use it to debug PHP scripts that are running on a remote server but you can do local stuff as well. It's not free, but assuming your own time is worth something, you will have gotten your money back within a few hours!
我使用 Komodo 5 --- 调试效果非常好,不仅使用 PHP,而且使用 Ruby 和 Python。我主要使用它来调试在远程服务器上运行的 PHP 脚本,但您也可以执行本地操作。它不是免费的,但假设您自己的时间有价值,您将在几个小时内取回您的钱!
回答by Aurovrata
If you are using MAMP, please note that it has 2 php.ini files that need to be updated. It took me hours to figure this one out. The two files are in the following folders for MAMP 4,
如果您使用的是 MAMP,请注意它有 2 个 php.ini 文件需要更新。我花了几个小时才弄明白这一点。这两个文件位于 MAMP 4 的以下文件夹中,
/Applications/MAMP/bin/php/php5.6.25/conf/php.ini
/Applications/MAMP/conf/php5.6.25/php.ini
if you're using php7 then you'll need to update those files instead. Scroll to the bottom of the files and make sure you have the following entries,
如果您使用的是 php7,那么您将需要更新这些文件。滚动到文件底部并确保您有以下条目,
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.6.25/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so"
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
Then make sure you restart your server else the new settings won't be loaded. To make sure Xdebug is working properly, open your MAMP Start page, and click onthe phpinfo tab. Search for xdebug in the listing, you should see the Xdebug sectionthat shows that the extension is loaded and enabled, else something is wrong with the above configurations.
然后确保重新启动服务器,否则不会加载新设置。要确保 Xdebug 正常工作,请打开您的 MAMP 开始页面,然后单击 phpinfo 选项卡。在列表中搜索 xdebug,您应该看到Xdebug 部分,显示扩展已加载并启用,否则上述配置有问题。
Next you can launch MacGDBp and it will connect to port 9000 and allow you to debug your files.
接下来,您可以启动 MacGDBp,它会连接到端口 9000 并允许您调试文件。
NOTE: If you are developing on Wordpress, then make sure you skip the 'AJAX' debugging sessions. These are regular as the Dashboard will ping the server for changes. If you enable the 'break on the first line' in MacGDBp settings, you will see the ajax sessions breaking on the line define ('DOING_AJAX')....which you can skip. Once you have then fire your event for debugging your code.
注意:如果您在 Wordpress 上进行开发,请确保跳过“AJAX”调试会话。这些是常规的,因为仪表板将 ping 服务器以进行更改。如果您在 MacGDBp 设置中启用“在第一行中断”,您将看到 ajax 会话在define ('DOING_AJAX')....您可以跳过的行上中断。一旦你触发了你的事件来调试你的代码。
回答by Gary Richardson
I guess I don't get bonus points, but Zend Studio works for me on my Mac connecting to Apache running in VMware.
我想我没有得到加分,但是 Zend Studio 在我的 Mac 上为我工作,连接到在 VMware 中运行的 Apache。
回答by phatduckk
I debug PHP CLI scripts and web probject (thru apache etc) using Eclipse & ZendDebugger all the time.
我一直使用 Eclipse 和 ZendDebugger 调试 PHP CLI 脚本和 web probject(通过 apache 等)。
I answered a similar question over at the following link: click here
我在以下链接中回答了类似的问题: 单击此处
Hopefully that's what you're looking for.
希望这就是你要找的。

