在 Mac 上调试 php?
想知道在本地计算机上调试 PHP 的最佳方法是什么。我在 mac os 10.5 上使用 MAMP
谢谢, 帕特里克
was wondering what was the best way to debug PHP on my local machine. I use MAMP on mac os 10.5
thanks,
Patrick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用 xdebug 是一个好的开始。下载软件包并按照
INSTALL
文件中的说明进行操作。这相当容易。完成此操作后,将以下行添加到您的php.ini
文件中:不要忘记在此之后重新启动 Apache。
大多数调试可以使用简单的
die(var_dump($some_variable))
来完成。它不是很复杂,但是安装了 xdebug 后,vardump 的输出在浏览器中看起来相当不错。在大多数情况下,这就足够了。如果您需要更多控制,可以在代码中添加
xdebug_break();
语句,并将以下几行添加到php.ini
中:同样,不要忘记重新启动阿帕奇。
现在,使用像 MacGDBp 这样的工具(或者 Eclipse+PDT,如果你必须的话),你会得到一个经典的调试器。您可以单步执行您的程序。
玩得开心!
Using xdebug is a good start. Download the package and follow the instructions in the
INSTALL
file. It's fairly easy. Once this is done, add the following lines to yourphp.ini
file:Don't forget to restart Apache after this.
Most debugging can be done using a simple
die(var_dump($some_variable))
. It's not very sophisticated, but with xdebug installed, the output of a vardump looks pretty good in a browser. In most of the cases this is enough.If you need more control, you can add an
xdebug_break();
statement in your code and add the following lines to yourphp.ini
:Again, don't forget to restart Apache.
Now, using a tool like MacGDBp (or Eclipse+PDT if you must), you get a classic debugger. You can step though your program.
Have fun!
我一直认为在任何平台上调试 PHP 的“最佳”方法是使用 FirePHP,它可以将调试消息直接输出到 Firefox 的 Firebug 窗口中。
I've always thought the "best" way of PHP debugging on any platform is by using FirePHP, which can output debug messages straight into the Firebug window in Firefox.
我发现在尝试在浏览器中重新加载页面之前运行
php -l myfile.php
非常适合捕获语法错误(从而防止令人讨厌的 死机白屏)。除此之外,我只需将浏览器指向本地网络服务器并尝试访问这些页面。您可以在代码本身中做一些漂亮的事情(例如使用 debug_backtrace() ),但这(显然)需要您自己将其放入代码中。
I've found that running
php -l myfile.php
is great at catching syntax errors before I try and reload the page in my browser (and thus prevent the abominable White Screen of Death). Beyond that, I just point my browser to my local webserver and try to access the pages.You can do some nifty things in your code itself (like using debug_backtrace()), but that (obviously) requires you to put it in the code yourself.
就我个人而言,我使用 Eclipse+PDT 和 XDebug。为了简化操作,请从 Eclipse 下载页面 获取 Eclipse for PHP Developers,而不是将 PDT 作为插件安装。 Eclipse 的学习曲线很高,但它为您提供了您期望的所有调试器功能:指令单步执行、断点、监视,甚至实时更改变量。
如果您不喜欢 Eclipse 或者发现它对您来说太多了,还有其他兼容的客户端使用 XDebug。
Personally, I use Eclipse+PDT and XDebug. To simplify things, get Eclipse for PHP Developers from the Eclipse download page rather than installing PDT as a plugin. Eclipse has a high learning curve, but it gives you all the debugger functionality you expect: instruction stepping, breakpoints, watches, even altering variables live.
If you don't like Eclipse or find it's too much for you, there are other clients compatible with XDebug.
我还使用eclipse+pdt和xdebug。如果您不熟悉调试器,可以尝试 zend studio这将很容易地设置事情。
I also use eclipse+pdt and xdebug. If you're new to trying out debuggers you can try zend studio which will setup things pretty easily.
Zend Studio 是迄今为止用于创建和调试 PHP 代码的最佳工具。我在我的开发 Linux 机器上运行 Zend Server 的社区版,并在我的 MacBook Pro 上的虚拟机中本地运行。
查看 Zend 网站了解详细信息 - 它使我的应用程序开发减少了三分之二!
Zend Studio is by far the best tool to use to create and debug PHP code. I run the community Edition of Zend Server on my dev Linux box and locally in a virtual machine on my MacBook Pro.
Take a look at the Zend website for details - it has cut my app development by two thirds!
感谢一堆像这样的链接和其他链接,这里有一个已编译的解决方案,它成功地将 OSX 的本机 Apache2 和 XDebug 与 MacGDBp 以及名为 XDebug 助手。
Thanks to a bunch of links like this one and others, here's a compiled solutions that successfully uses OSX's native Apache2 and XDebug together with MacGDBp and a Safari extension called XDebug Helper.
即使没有 MAMP,您也可以做到这一点。
有一种方法可以使用:
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/安装/master/安装)"
Php + Xdebug
1) 安装 php 并调试
在 PhpStorm - 检查首选项 =>;语言和框架 => PHP
PHP语言水平:7
解释器:PHP 7.0.8 + XDebug(或从 [...] 中选择)
检查调试配置:
偏好=>语言和框架 => PHP=>调试=> X调试部分
应选中所有复选框并将调试端口设置为:9001
2) 在应用程序目录中运行服务器:
3) 将 localhost:8080 添加到 PhpStorm Preferences =>语言和框架 => PHP=>服务器:
名称: 本地主机:8080
主机:本地主机
端口:8080
调试器:Xdebug
4) 更新 php.ini:
php=>翻译=> […] =>配置文件 - 在编辑器中打开
添加此部分:(通过cli检查zend_extention路径)
5)添加调试配置:
运行=>编辑配置=>添加 - Php Web 应用程序
6) 单击开始侦听 Php 调试连接
7)设置断点
7)单击“调试”(绿色错误)
You can do it even without MAMP.
There is a way how to do it using:
Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Php + Xdebug
1) Install php and debug
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
2) run server in your app's directory:
3) Add localhost:8080 to 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)
5) Add Debug Configuration:
Run => Edit Configuration => add - Php Web Application
6) Click Start Listening for Php Debug Connections
7) Set up breakpoints
7) Click on Debug (Green bug)