PHPStorm Remote Deployment & CLI Debugging

I’ve long preferred doing web development on my local laptop. Unfortunately, my current consulting gig has strict requirements. Specifically, I’m again migrating content from an Oracle database into Drupal 8. This time, the Oracle database is behind an IP based VPN - I can only connect to it via a specific AWS instance that’s running our Drupal 8 site. My PHP has to run at AWS, and can’t run locally. Happily, PHPStorm thrives in this situation. PHPStorm Deployments sync code from my laptop to AWS via SSH. Further, I’ll show how to configure the Debugger to step through remote execution of PHP CLI scripts. Remember kids, the debugger is your friend.

This blog is a terse “how-to”. Refer to Sync changes and automatic upload to a deployment server in PhpStorm and Remote Debugging in PHPStorm via SSH Tunnel for more detail.

Remote Deployment

  1. Start creating a new Deployment configuration: Tools => Deployment => Configuration
  2. Enter a name and pick SFTP for the type.
  3. On the connection tab, enter the SSH details for remote server.
  4. On the Mappings tab, tell PHP storm how the remote path maps to the local path. In my case:
    Local path: /Users/moshe.weitzman/reps/b4
    Remote path: /var/www/drupal
  5. Test by browsing the remote host: Tools => Deployment => Browse Remote Hosts
  6. You may now upload from local to remote via Tools => Deployment => Upload To [name]. Explore other options in this menu that may better suit your use case.

Remote Deployment example

Remote CLI Debugging over an SSH Tunnel

On your local machine:
  1. Run => Start listening for PHP Debug Connections
  2. Run => Break at the first line in PHP scripts
  3. In a terminal on local machine, run a command like ssh -R 9000:localhost:9000 -A username@host. The -R arguments creates a SSH tunnel such that port 9000 on the remote server forwards all traffic to port 9000 on your local machine. This neatly bypasses any networking challenges between you and the remote machine. Customize username@host for your own needs.
On the remote server:
  1. Enable and configure the Xdebug PHP extension on the remote server. Use php --ini to figure out which ini file to edit. Then add:
  2. Use php -i | grep -i xdebug to verify that your edits are working (i.e. remote_enable is enabled).
  3. In a terminal on the remote server, run a PHP CLI script such as XDEBUG_CONFIG= vendor/bin/drush st. The first clause sets a required environment variable to null value. We only need this variable to be defined. It triggers XDebug to connect back to PHPStorm.
  4. If prompted about Path Mappings, choose to pull them from the Deployment specified above.


If you get stuck, I refer you again to these longer documents: Sync changes and automatic upload to a deployment server in PhpStorm and Remote Debugging in PHPStorm via SSH Tunnel.


Sridhar balasubramanian November 24, 2017

Hi weitzman,

Thank you very much. Me too have deployment server in remote. This article helped me lot.

Cheers, Bala