SFTP folder sync for remote PHP debug with VSCode


There are several VSCode SFTP or SSH extensions. I’ve tried a few. One I like is SSH FS ( https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs ). This one has some handy features, remote terminal quick access and remote folder explorer. I can’t, however, see how to use with local file folders that sync, in part to debug my PHP with it.

I use another extension, “SFTP” ( by liximomo ), that’s a little simpler and easier, but more importantly it provides a direct folder sync with my local filesystem. This makes it easy to do remote debugging. (Note: I use a separate terminal with local port forward ssh, where I set Xdebug in PHP to use that port to forward back to my local system to VSCode.)

In my project, inside the .vscode folder, I create a sftp.json settings file:

I like the way this works because I have many remote PHP projects running on that server but many folders I don’t want to sync. Using the “Ignore” settings its easy to exclude remote folders and files.

The workspace folders are created locally. With that I right click and pick “Sync …” or “Download Folder” to get the remote contents copied locally and/or synced.

When I edit files, they upload on save (If set that way in the sftp.json file).

For debugging, providing I have my ports set remotely and SSH connection set to use them, the debugging remotely works as if I were local.

Ssh client config option, using Xdebug port 9000 on remote server: RemoteForward 9000 localhost:9048

Now just create breakpoints and start listening to debug in VSCode.