Debug a remote server with XDebug and PHPStorm
The IDE (e.g. PHPStorm) is runnung in the local machine and is listening for XDebug connections from a remote server.
XDebug port: 9000
Redirecting all requests from the server that come to port 9000
to the local machine on port 9000
ssh -R 9000:localhost:9000 server_ip_hostname_or_config_alias
If the XDebug runs within a Docker container in the server, setup the tunnel with the command:
ssh -R \*:9000:localhost:9000 server_ip_hostname_or_config_alias
This makes the tunnel open to the public.
By default, OpenSSH only allows connecting to remote forwarded ports from the server host Edit the
sshd_config
sudo joe /etc/ssh/sshd_config
Set
GatewayPorts yes
And restart SSH
sudo service ssh restart
Confirm that port 9000
accepts connection from any host
Run
sudo netstat -plnt
And confirm that you get 0.0.0.0
in the Local Address.
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 49998/sshd: skounis
In the local machine start a server that is listening to port 9000
nc -l 9000
In the server connect to port 9000
and send some messages (text)
nc localhost 9000
Any character we type should apear in the terminal in the local machine.
Go to "Preferences > Build, Execution, Deployment > Deployment".
And set
Go to "Preferences > Languages & Frameworks > PHP > Servers".
You need to have an exact copy of the files in the local filesystem.
- Set the IP of the server
- Map the files by using absolute paths for local and remote folders.
Select "Run > Web Server Debug Validation"
- Select Remote Web Server
- Set the path to the folder that is server by the webserver
- Select the Deployment server
- Press "Validate"
Select the PHP Server and start listening for connection.
Install a plugin that sets the debug session
Visit the public URL with the plugin enabled.
PHPStorm expects the cookie value XDEBUG_SESSION=PHPSTORM;
in the request header.
- Sending TCP/UDP packets using Netcat
- Understanding and using Xdebug with PHPStorm and Magento remotely
- SSH Port Forwarding Example
- Check listening ports
- How to make ssh tunnel open to public?
- SSH Tunnel - Local and Remote Port Forwarding Explained With Examples
- sshd_config - SSH Server Configuration