27

I have tried:

  1. Xdebug and Eclipse. Eclipse launches a web browser, but the browser tries to access a non-existent file in Eclipse's .app bundle.
  2. 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.
  3. 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.
  4. 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.

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 -i in the CLI.

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 without using some bloatware editor like Eclipse, or that expensive proprietary thing Zend wants to sell me.

My server is connecting to PHP via FastCGI, if that makes a diff.

Garrett Albright
  • 2,844
  • 3
  • 26
  • 45

8 Answers8

21

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 help section, 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.

Brian Benzinger
  • 326
  • 3
  • 4
  • Now that looks *really* nice. But it too requires PHP 5, which I don't have access to at work. I can't wait to give it a try at home, though. Five hours, eighteen minutes and thirty-three seconds to go… – Garrett Albright Sep 17 '08 at 18:41
  • I've been looking for something like this on Mac OS X. – Devon Sep 17 '08 at 19:46
  • Okay, this is pretty epic. I'm going to have to insist to my boss that I install PHP 5 (and 10.5) on my machine at work so I can use this. Mad props, Brian. – Garrett Albright Sep 18 '08 at 04:18
  • 1
    This has a TON of frustrating bugs on PHP 5.3.3 w/ Xdebug 2.1.0. The author seems nonresponsive. It's unusable for all but the most trivial of debugging. – hobodave Oct 13 '10 at 18:12
  • I found http://xdebug.org/find-binary.php very helpful to get XDebug installed the PHP that ships with OSX. – drewish Sep 17 '11 at 19:11
11

Here's how I did it:

1 - Copy the latest version of xdebug.so from http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging to /usr/libexec.

2 - Add the following to the global 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.

Luke Dennis
  • 14,212
  • 17
  • 56
  • 69
3

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

Henrique B.
  • 450
  • 3
  • 9
  • I can't figure out how to get it to work. It doesn't seem to halt on the first line of execution like MacGDBp, and I can't find a way to insert a breakpoint - dragging files to the Breakpoints list or app icon does nothing, and clicking the + icon by the list just inserts an empty row. Trying to bring up the help box returns the classic "Help isn’t available for [app name]" - acceptable for an OSS freebie, but not for an app that wants me to pay for it. (Likewise, the text on the web page needs polish - "OSX," "mac," comma splices.) Back to MacGDBp for me. – Garrett Albright Oct 18 '12 at 07:32
  • You need to check "Break on first line" settings to make it break on first line. For the files you have to press CMD+E. The other things you mentioned are being added while I posted this. An update will be released in the next few days to address file/folder dragging, help, and a few other things. Btw documentation you can get it here: http://codebugapp.com/support – Henrique B. Oct 18 '12 at 10:42
  • I actually like that it doesn't break on the first line like MacGDBp, which *always* breaks on the first line. – wizonesolutions Mar 06 '13 at 14:43
  • Break on first line is an option in Codebug, you can turn it on and off in the preferences. – Don Nov 02 '16 at 20:21
  • Codebug has been discontinued according to MacUpdate (https://www.macupdate.com/app/mac/45824/codebug), and the website is currently showing a parked/domain for sale type message. – star-szr Jun 10 '17 at 14:27
1

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!

David
  • 5,991
  • 5
  • 33
  • 39
1

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)

Arif Dewi
  • 2,222
  • 26
  • 14
0

I debug PHP CLI scripts and web probject (thru apache etc) using Eclipse & ZendDebugger all the time.

I answered a similar question over at the following link: click here

Hopefully that's what you're looking for.

Community
  • 1
  • 1
phatduckk
  • 1,775
  • 1
  • 14
  • 17
0

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,

/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,

[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 section that shows that the extension is loaded and enabled, else something is wrong with the above configurations.

Next you can launch MacGDBp and it will connect to port 9000 and allow you to debug your files.

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.

Aurovrata
  • 2,000
  • 27
  • 45
0

I guess I don't get bonus points, but Zend Studio works for me on my Mac connecting to Apache running in VMware.

Gary Richardson
  • 16,081
  • 10
  • 53
  • 48