Debug WordPress with Eclipse PDT and Xdebug

I have set up my local development machine (Mac Mini(late 2014) , El Capitan 10.11.6) for WordPress PHP development and debugging, specifically for WordPress Plugin Development. I prefer to to use Eclipse PDT and Xdebug for debugging.

 

We use our own internal POMAMA, script to configure our workstations, which automatically configures Apache, mySQL and few other components we use. I also have HomeBrew installed on my mac.

 

We also use our quick start guide to install WordPress for local development  on your development machines.

 

The only issue I had really was configuring Eclipse PDT for debugging using Xdebug. This was due to little gotcha’s , I ran into initially that I lost a bit of time on so I thought I would document this with the hope of saving somebody else time. (Always believe in paying forward 🙂 )

 

Install Xdebug via HomeBrew

In my particular instance we are developing and testing for WordPress using PHP 7.0 , if you looking for a particular PHP version of xdebug simply swap out the version numbers

Install xdebug-osx

Due to the fact that a few of PHP frameworks, in our case CakePHP and Laravel, all need xdebug to be deactivated for when they do generation, it install a handy little CLI program to toggle Xdebug on and off.

This enable to simply switch xdebug on or off from the terminal :

 

 

Edit Xdebug Config

We need to make a few edits to the xdebug configuration, if you’re using POMAMA, you can get the information as regards it’s location from PHPInfo,

xdebug.ini config

We’ll use nano to edit this file, these are the settings that worked for me. You may want to edit them for your environment

 

 

xdebug.ini changes

Restart Apache

We now need to restart our apache webserver for the changes to take effect.  Ensure you have toggled xdebug to on before you restart.

Eclipse Configuration

Open your eclipse PDT and open your WordPress Project . We make use of Eclipse Neon internally so the screens may look a little different depending on your version of Eclipse. I am assuming you have created a new PHP Project and imported your WordPress installation.

 

Configure a new PHP Web Application debug configuration

screen-shot-2016-09-13-at-15-58-10

 

Configure the debugger to be xDebug and configure it to use the same port as you set as the remote_host in xdebug.ini

 

screen-shot-2016-09-13-at-15-58-51

 

Uncheck the Break at First Line checkbox, as you don’t really want to step through 1000’s of lines of code to get to your issue 🙂

 

screen-shot-2016-09-13-at-15-59-12

Enter your base URL for your wordpress installation.

In our case we make use of dnsmasq to create local dns names so our base url is usually http://wordpress.dev.  If you followed our links earlier your setup should be similar.

 

screen-shot-2016-09-13-at-16-00-06

 

You can now click finish.

Start Debugging

You should now be able to place a break point at any area of the code your interested in, hit the debug and open the Debug Perspective.

Top Tip

If you run into issues with a “Waiting for Debug”  play around with the port numbers, but usually 3001 works well for us.

Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me

Latest posts by Gary Woodfine (see all)

π
%d bloggers like this: