debugging php on mac?

こ雲淡風輕ζ 提交于 2019-12-04 11:44:58

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 your php.ini file:

;;[xdebug]
zend_extension="/Path/to/your/module/xdebug.so"
xdebug.file_link_format="txmt://open?url=file://%f&line=%1"
xdebug.var_display_max_depth = 20

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 your php.ini:

xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1

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!

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.

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.

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.

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.

Alan

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!

perso58jm

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.

You can do it even without MAMP.

There is a way how to do it using:

1) Install php and debug

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

2) run server in your app's directory:

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

4) Update php.ini: Php => Interpreter => […] => Configuration file - Open in Editor Add this section: (check zend_extention path through the cli)

[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

  • Choose Localhost:8080 server

6) Click Start Listening for Php Debug Connections 7) Set up breakpoints 7) Click on Debug (Green bug)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!