Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debugging php on mac?

was wondering what was the best way to debug PHP on my local machine. I use MAMP on mac os 10.5

thanks, Patrick

like image 949
patrick Avatar asked Jun 19 '26 08:06

patrick


2 Answers

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!

like image 96
Pierre Spring Avatar answered Jun 20 '26 20:06

Pierre Spring


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.

like image 24
tom Avatar answered Jun 20 '26 20:06

tom