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:
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: