You may want to xdebug site on remote server, maybe you dont even want to run site locally but just have remote server running the site and codebase to all be there. You could have development server running on some hosting. To do that first you need to
1. Install "Remote - SSH" VS extension which will give you this feature as it says in description "Open any folder on a remote machine using SSH and take advantage of VS Code's full feature set".
2. You should then open your site with this extension
3. After that you need to setup php xdebug extension on your remote server and put proper config, this one is for xdebug 3.x
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.client_host = 75.316.6.96
most important part is client_host which needs to be set as your server IP and not localhost which is default.
4. After that you just need to make proper launch.json file for debug in VS code where we put this IP address, like here
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"hostname": "75.316.6.96",
"port": 9000,
"pathMappings": {
"/var/www/site": "${workspaceFolder}/",
}
}
]
}
5. Launch the debugger, put breakpoints where you want it and should work.
If you are doing this on production you should disable xdebug module once you are done as this slows down the site. To do that use sudo phpdismod xdebug and once you want to use it again run sudo phpenmod xdebug.
Just remember to restart php with sudo service php7.2-fpm restart or similar