A short tutorial on how to set up Xdebug with VSCode running a local server using MAMP Pro.
For this video we are going to learn how to set up Xdebug with PhpStorm running a local server on MAMP Pro. Xdebug runs via MAMP Pro, as a PHP extension, so the first we need to do is enable Xdebug in our MAMP Pro configuration.
To enable Xdebug in MAMP Pro, we need to access the PHP settings via the MAMP Pro app.
This enables Xdebug so it is running as a PHP extension. Now it will be available to call back to our IDE on port 9000 when it receives a HTTP request.
PhpStorm has a zero-configuration feature for Xdebug and with MAMP Pro it seems to work nicely out-of-the-box, so you should be able to accept its settings and then continue on with your setup.
The first step we need to take is to get VSCode setup to handle Xdebug debugging sessions. Let’s install the extension called php-debug, which gives us the interface for setting up and managing Xdebug connections from our DDEV server.
In VSCode, go to Extensions (shift-command‑x on the Mac). Search for php-debug
and choose the one by Felix Becker. It should have millions of downloads.
Go to the Run and Debug section of Code. And we want to create a launch.json
file. In VS Code, a launch.json
file tells VS Code debugger which debugging configurations it should provide in the debugger. We want to create a debugging configuration just for Xdebug and our server running on MAMP Pro.
Once we click “create a launch.json file”, then we’ll get the code editor with that file open. If, for some reason, it doesn’t open, then you can access it inside your project files.
No we want to add a new configuration to the file. We can do this via the “Add Configuration…” file at the bottom of the screen or just paste in the code below:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"hostname": "yourhostname",
"port": 9000,
}
]
}
Replace the yourhostname
in the hostname setting for the hostname of the MAMP Pro project you’re running. For me, that would be xdebug-mamp
. If you don’t know, you can look at the Hosts section of MAMP Pro to get the list of hostnames.
And then save the file. You should see the Run and Debug pane change and now recognize the new configuration for listening for Xdebug connections.
VS Code is now configured to listen on port 9000 for Xdebug connection.
Debugging with Xdebug is made up of the following videos: