DEV Community

peerhenry
peerhenry

Posted on

Setup Xdebug on WSL

How to setup xdebug in Windows Subsystem for Linux (WSL). Open your terminal and let's get cracking!

1. Update pecl
sudo pecl channel-update pecl.php.net

2. Install xdebug
sudo pecl install xdebug

3. Find xdebug.so
cd /usr
find . -name xdebug.so
In my case it was /usr/lib/php/20180731/xdebug.so

4. Edit your php.ini
Edit the php.ini file for the php version you are using. I had to edit /etc/php/7.3/cli/php.ini but you may be using a different version. If you are unsure, you can find out by running php -i|grep 'php.ini' in the terminal. That should show you where to find you active php.ini file. Now add the following lines to the end of that file:

[Xdebug]
zend_extension="/usr/lib/php/20180731/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000

But make sure you enter the correct path to xdebug.so specified in step 3. Choose another port if you feel like it.

5. Setup VSCode
If you are using VSCode like I do, this last step is for you. Inside your project folder, check if you have a folder .vscode that contains launch.json. If not, click the run button on the left panel. Then click on "create a launch.json file" and select "PHP". In case your project is located in your windows file system instead of your WSL file system - which is the case for me - make sure you add pathMappings.

"pathMappings": {
    "/mnt/<DRIVE>/<PATH_TO_PROJECT>": "<DRIVE>:\\<PATH_TO_PROJECT>"
},

In my case my launch.json looks like this:

{
  "version": "0.2.0",
    {
      "name": "Listen for XDebug on WSL",
      "type": "php",
      "request": "launch",
      "pathMappings": {
        "/mnt/c/infi": "C:\\Infi"
      },
      "port": 9000
    }
  ]
}

Make sure the port matches with the one you specified in step 4. Happy debugging!

Top comments (3)

Collapse
 
jmcelreavey profile image
John McElreavey

You sir are a legend, I spent ages trying to figure this out. PHPStorm was working fine but VSCode wasn't adding:

xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
Enter fullscreen mode Exit fullscreen mode

Fixed everything!

Collapse
 
troyclose profile image
Troy Close

Thanks for the info. I didn't know about "channel-update pecl.php.net" before trying to install the package. Also there seems to be a bug in PEAR/REST.php on line 187 which I was getting as well. I commented out the offending line as a temp fix to install, but need to do a followup and put in a decent patch. If anyone else gets this error, there is a post on SO
stackoverflow.com/questions/597206...

Collapse
 
vionikolov profile image
VioNikolov

I've just created account to say THANK YOU!
This was what I was missing:
zend_extension="/usr/lib/php/20180731/xdebug.so"