Debugging PHPStorm on Windows with Amazon Web Services

[I've checked the forums here, but there doesn't appear to be a recent thread about this subject. I've looked a the tutorials and didn't see anything; there's Cloud Services (but that's Azure), there's another for Google, but nothing for AWS.]

I'm developing some command-line PHP scripts on Linux virtual hosts at Amazon.

I'd like to be able to debug them using PHPStorm (v7.1.3) without putting var_dump and print_r all over the code.

Right now my workflow is to edit on the PC, send to github. On the Linux VM, I do a git pull and then run the code.

So I've got a SSH tunnel working with putty, but I'm confused on what specifically I'm supposed to configure in putty, xdebug and PHPStorm to allow me to debug.


Comment actions Permalink

I have ssh setup to remote forward port 9000 on the AWS EC2 instance back to the host that has PHPStorm running on it.

I've clicked the "Listen" icon in PHPStorm.

In the debugger window I have "Waiting for connections from Jetbrains IDE Support Extension for Chrome), but this is a command-line program, so Chrome isn't involved.

I've started to run the CLI program on the EC2 host, but a PHP error isn't causing PHPStorm to do anything.

I've also tried to set a breakpoint in PHPStorm and run the program on the AWS host, but the breakpoint isn't triggering.

I believe that the xdebug is configured properly:

$ php -i | grep "xdebug"
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.idekey => no value => no value
xdebug.max_nesting_level => 100 => 100
xdebug.overload_var_dump => On => On
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => Off => Off
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.scream => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

Comment actions Permalink

1) Have you defined "PHP_IDE_CONFIG" environment variable ?

2) You will also need to configure xdebug a bit -- right now it is NOT configured at all (based on what is your "php" -i shows).

  • xdebug.remote_enable MUST be ON
  • to automatically start debug session (xdebug.remote_autostart must be ON) .. unless you can provide debug marker somehow manually

3) You may also need to configure xdebug.remote_host and xdebug.remote_port -- I'm not using SSH tunneling so cannot advice here -- better search for more info on this in this froum or google.

If not SSH tunnel will be in use .. then these 2 settings definitely need to be configured with your IP (where PhpStorm is running, as seen from remote host) as well as ensure that xdebug can connect to PhpStorm (firewall settings / port forwarding on router etc)

Also -- have you seen this comment: ?

Comment actions Permalink

OK, this is now working. What I needed to do.

In putty, configure the SSH tunnel so that traffic to port 9000 on the EC2 host is sent back to you.

Add new Forwarded port
Destination:localhost:9000 "Remote"

Save session.

Logout of any existing ssh tunnels and then restart your SSH session.

If you're running an Ubuntu VM:

sudo apt-get install php5-xdebug

sudo bash
cat >> /etc/php5/mods-available/xdebug.ini


You'll probably want to set these in your .bashrc

export XDEBUG_CONFIG="idekey=phpstorm"
export PHP_IDE_CONFIG="serverName=aws"

In PHPStorm:

Run->Edit Configurations->Defaults->PHP Remote Debug
Servers: Click the "..."
Hit the "+" to add
Name: whatever you configured for "serverName" (aws in this example)
Host: localhost
Port 9000
Debugger Xdebug

Click "Use Path Mappings"
Click on the php file you'll be debugging (in my case, process-JSON.php). The field next to it will then have a "notepad" icon; click that: "Absolute Path on the server". Make sure that it's correct. For me it's /home/ubuntu/code/JSON/process-JSON.php
Click Apply, then OK
In the Ide key(session id) field, put in phpstorm

In the PHPStorm IDE, click the telephone "listen" icon.
In Run->Break in first line in PHP scripts

The "Break" command means that once you run the CLI script on the Linux host, you should see that PHPStorm take you to the first line of your script and is now waiting for you to start stepping.

On the EC2 instance, start running your program.

I'll double-check the above steps when I try to replicate later tonight.

Message was edited by: Robert Kulagowski


Please sign in to leave a comment.