PhpStorm
 
Get PhpStorm

Debug a PHP CLI script

Last modified: 11 October 2024

PHP applications are not always web applications. Various command line tools, daemons, message queue processing applications and other types of applications typically run in the PHP CLI. There are several ways to start a PHP CLI debugging session. You can start it from within PhpStorm and make it start the script and attach the debugger to it. Alternatively, you can let PhpStorm listen for incoming debugger connections and start the script outside the IDE. We'll take a look at both options.

Before you start debugging, make sure that you have a debugging engine installed and configured properly. PhpStorm automates the process of getting Xdebug up and running. On your first attempt to run a debugging session without a debugger installed, the IDE will prompt you to download and install the relevant version of Xdebug.

Download and install Xdebug extension

Click Download and install the Xdebug extension to have PhpStorm download Xdebug and modify the relevant PHP configuration file. If you want more control over the installation process, click Generate installation script and run the commands manually.

Alternatively, you can install and configure the debugging engine manually as described in Configure Xdebug and Configure Zend Debugger.