Hi Everyone,
Recently, I was struggling to set up remote debugging on VS code and I thought my experience can help someone. So here is the steps for so.
- Install VS code
- Install Xdebug on your system. click here for instructions. Add xdebug config to php.ini files
- Install PHP debug on VS code . click here for instructions.
- Go to your project folder, create new folder called .vscode
- Create launch.json file. This is config file for your debugging. You can update this files with the code given on 5.1.
- Add breakpoints to the place you want to visualize the process
- Click debug on left sidebar panel
- On the left top select option Listen for Debug > Click run and debug
You can follow through the VS code debug option on left navigation menu and select launch.json file for config.
1.1
[This config is written for old version 5.5 PHP version and 2.5.5 Xdebug version] [xdebug: This config goes to php.ini files] xdebug.remote_enable=on [This is specifically for docker, you can use localhost instead of host.docker.internal] xdebug.remote_host=host.docker.internal xdebug.remote_connect_back=off xdebug.remote_autostart=on xdebug.remote_port=9001
For latest Xdebug config there is no much change in it, it’s just values we need to change above. Please refer to this articles.
5.1 So here comes final steps
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9001, "pathMappings": { "/var/www/html": "${workspaceRoot}/src/public" } }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9001 } ] }
If you are getting any error like endpoint not available or breakpoint not available, please check if you need pathmapping. Mostly while using with Docker we need to map docker files to local files.
I hope this helps.
Thanks