Though I’m not a fan of strictly using var_dump or echo statements as a way to debug code, that doesn’t mean there aren’t times in which they are useful (otherwise, they wouldn’t be part of the language, right?).

But what if you’re using Laravel Valet (which is easy enough to setup for WordPress) and you’re trying to display some multidimensional array and rather than getting some nicely formatted output, you end up getting one long line of text in Times New Roman? Odds are this is because you don’t have Xdebug.

Using Xdebug with Valet and WordPress: Valet

It’s easy enough to do, but it’s predicated on a few different things. Plus, once you get Xdebug installed, then you’re able to use a debugger with your code, as well. That’s not the point of this post, though. 🙂

Xdebug with Valet and WordPress

Getting all of this setup is easy enough, but it assumes the following:

  1. You’ve got all of the necessary constants set up for WordPress debugging,
  2. You have Homebrew installed on your machine,
  3. You’re comfortable editing a text file (technically, an initialization file for Xdebug, but text nonetheless)
  4. You’re okay restarting Valet.

To make sure that you’ve got WordPress configured to properly show debug messages, make sure that wp-config.php (or whatever file maintains your constants) has the following:

Note that there are other constants you can use, but these are two that I’m normally a fan of including at a minimum.

Using Xdebug with Valet and WordPress: Homebrew

From there, install Homebrew. It’s as easy as the following command, but I recommend reading both this article and the homepage before executing it:

/usr/bin/ruby -e "$(curl -fsSL"

Once done, you’ll need to install Xdebug. This assumes that you’re running PHP 7.1. If not, you’ll need to install the package that’s correct for your version of PHP. But assuming that’s accurate, issue the following in your terminal:

$ brew install php71-xdebug

Once Homebrew is done, use a text editor to load up the configuration file for Xdebug. To do this, drop the following line in your terminal:

$ atom /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini

Then add the following lines:

This will configure Xdebug, so browser output is readable and so that you can use things like Xdebug actually to debug your code. After that, to take advantage of Xdebug with Valet and WordPress, you’ll need to restart Valet:

$ valet restart

And once done, you should be good to go.


Join the conversation! 1 Comment

  1. Hi Tom,

    Great article. Do you have some tips about how to make the environment work with Visual Studio Code?

    I’m a WP dev and I have a setup a WP site on Valet. I’m not able to debug my plugin directly on VS code.

    Any tips about that?

    Thank you

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.