For example drush cc all or php /root/drush/drush.php status
On the command line run the command you want to run.
export PHP_IDE_CONFIG="serverName=yourservername" - the serverName is the name of the "server" you configured in PHPStorm above, which does the mapping of remote to local paths.
If you're not tunneling, it must be the reachable IP address of the machine where PHPStorm is listening. For example, export XDEBUG_CONFIG="idekey=PHPSTORM remote_host=172.16.1.1 remote_port=9000" (Note that port 9000 is the default both for xdebug and for PHPStorm.) If you're tunneling the connection then remote_host must be 127.0.0.1.
In your command-line shell session on the remote server set the environment variable XDEBUG_CONFIG.
ssh -R 9000:localhost:9000 For more details and debugging, Remote Drupal/PHP Debugging with Xdebug and PHPStorm
If the computer is not reachable from the server, you will need to tunnel the connection from the server to your workstation.
For example, if you're debugging most drush actions, you could put a breakpoint on the first line of drupal_bootstrap() in includes/bootstrap.inc.
In PHPStorm, set a breakpoint somewhere that your PHP script is guaranteed to hit early in its execution.
See Remote Drupal/PHP Debugging with Xdebug and PHPStorm I call this the "unconditional listen" button, because it makes PHPStorm listen on port 9000 and accept any incoming connection, no matter what the IDE key.
Click the "Listen for PHP Debug Connections" button in PHPStorm.
ssh -R 9000:localhost:9000 - For more details and debugging, see
If your remote server cannot directly create a tcp connection to your workstation, you'll have to tunnel port 9000 to your local machine.
Click "Use path mappings" and configure the mappings from your project to the remote server's code. Run->Edit Configurations, Create PHP Web App, Create a server, give the server a name.
#Phpstorm debugging code
The Server configuration is used to map code locations from the server to your PHPStorm code.
Create a debug configuration and a "Server" configuration in your project.
PHPStorm is quite insistent that executing code must be found in the project.
If you're debugging drush, you probably need to copy it into your project (you don't have to add it to source control).
(You can optionally mount the remote source locally and open it in PHPStorm using sshfs or any other technique you want, see notes below.)
Open your project/directory in PHPStorm it must have exactly the same code as is deployed on the remote server.
For complete details see Remote Drupal/PHP Debugging with Xdebug and PHPStorm.
#Phpstorm debugging install
On the remote server install xdebug and set xdebug.remote_enable=1 In your xdebug.ini (or php.ini).
Run the command-line tool on the remote server.
Create a breakpoint somewhere early in the execution path.
Tunnel the Xdebug TCP connection if necessary.
Use environment variables on the remote machine to tell xdebug what to do with the debugging session.
Create a mapping from server side directories to PHPStorm-side code (A "Server" configuration in PHPStorm).
This can be done via source control with matching code, by mounting the remote directory to your local machine, or any way you want.
We'll create a PHPStorm project that contains all the code we want to debug on the remote machine.
Just enter PHPStorm's Run/Debug configuration and create a new "PHP Script" configuration. Note: If you just want to debug a PHP script (or drush command) on the local machine, that's much easier. You just have to set up a couple of environment variables, map the remote code to the local code that PHPStorm has at its disposal, and tunnel the xdebug connection to your workstation. XDebug with PHPStorm can do step-debugging on remote sessions started from the command line on a remote machine.