Skip to content

Instantly share code, notes, and snippets.

@dorelljames
Last active June 25, 2021 13:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dorelljames/fcd5abb63b3337ff3218f1d7b738cc53 to your computer and use it in GitHub Desktop.
Save dorelljames/fcd5abb63b3337ff3218f1d7b738cc53 to your computer and use it in GitHub Desktop.
OS X: Configuring XDebug on Visual Studio Code

OS X (MacOS): Configuring XDebug on Visual Studio Code

This guide is intended to get you up and running with XDebug for Visual Studio Code on OS X.

My Setup

  • Visual Studio Code (Insiders) 1.10.0
  • OSX El Capitan 10.11.6
  • PHP 7.0.15 (installed via homebrew)
  • XDebug 2.5.0 (installed via homebrew)
  • Homebrew

Pre-requisite Installation

  1. Download latest Visual Studio or Visual Studio Insiders
  2. Install PHP. homebrew install php7
  3. Install XDebug homebrew install xdebug

Configuration

By default when XDebug is installed via homebrew, the extension will be automatically added/loaded as its configuration file /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini is additionally parsed; at least on my setup. If not, proceed below.

XDebug Configurations

  1. Locate configuration file for XDebug or locate php.ini.
  2. Either of the two above, make sure you configure the following below:
[xdebug]
zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9090;

Mine happens to use port 9090 as the default 9000 is in use by I don't know which program. To check whether the port is available, use the following command below in the terminal.

Command: netstat -an | grep <port>. E.g. netstat -an | grep 9000

Lastly, make sure to restart webserver. Enjoy!

Troubleshooting

  1. Debug adapter process has terminated unexpectedly. - First make sure that the port is available. A similar error EARINUSE is the same cause for this. Tweak your launch.json to match your XDebug port configuration. Mine uses 9090 to my I configured my launch.json debug settings file to use 9090.
  2. PHP Not Found - This goes that you need to tell VS Code where your php is installed. Use which php command in your terminal to get the path and go to VS Code > Preferences > Settings. Add the following line below in your user configuration file. Mine happens to be located at /usr/local/bin/php" so there you have it below:

"php.validate.executablePath": "/usr/local/bin/php"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment