Debug CLI Scripts with XDebug and PHPStorm

This is a quick how-to guide on setting up XDebug debugging for command line scripts. I felt it took me way too long to set it up, so I’m documenting it here. This guide assumes that you already have XDebug set up, and just need to enable CLI debugging.

 

XDebug Config

Run this command to add XDebug config to your environment variables. Note that this is for Windows.

 

PHP.ini Config

Add these options under the XDebug section in your php.ini file.

 

Restart Apache

Restart your Apache service.

 

Debugging Configuration

Now add a new debugging configuration in PHPStorm. IMPORTANT: The debug config type must be PHP Remote Debug. Choose your local server as the from the servers drop down.

RemoteDebug

Click OK.

Debug

Your command line debugging should now work. Select your new debug config from the drop down and enable listening for debugging connections. Add a break point in your CLI script, and voila!

RemoteDebugRun