Debugging PHP CLI scripts in PhpStorm which are running inside a remote server

Submitted by Peter Majmesku on Mon, 08/29/2016 - 20:18

Please notice: This article is for debugging with Xdebug. Not any "old-fashioned" debugging with var_dump(); or print_r() or any other "90ies webmastering style".

Remote debugging by SSH tunnel and the PhpStorm debugger

Additional settings in /etc/php5/cli/php.ini:

xdebug.remote_enable=true
xdebug.remote_autostart=true
xdebug.remote_port=9000
xdebug.remote_connect_back=1

 Then connect to your server via SSH tunnel (I have used a Vagrant box as an example, but you can tunnel into any server):

ssh -R 9000:localhost:9000 username_goes_here@hostname_goes_here

Start a script via PHP from the command line and PhpStorm will react (debugging button in PhpStorm must be turned on and the mapping for the directories must be set).

Remote debugging by the PhpStorm tools

In case that the debugger window will be opened, but the execution point will not be shown, you can run the script from PhpStorm itself.
Firstly you have to set up the remote debugging (Preferences > Languages & Framework > PHP). Choose here a remote interpreter.

If you have not already done so, set it up. The "SSH Credentials" settings have worked for me. While I'm using Vagrant and PhpStorm has an extra Vagrant checkbox (which has not worked for me):

In your PHP command line programs you need to specify often arguments. That can be done also:

Tags

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.