Configure Xdebug for PHPStorm: PHP’s Built-In Server

mrl7qwwkcie

PHPStorm is awesome. PHPStorm with Xdebug is even better. Specifically, when using Xdebug with the built-in PHP server. To Get Xdebug working in PHPStorm take these three steps:

  1. Step 1: In PHPStorm set the Xdebug port to 9003 under Preferences | Languages & Frameworks | PHP | Debug. In older versions of Xdebug port 9000 was the default but that port conflicts with php-fpm. Port 9003 is what you will want.
  2. Step 2: Install Xdebug if you don’t have it installed yet (macOS user install Xdebug and PHP using this guide).
  3. Step 3: Ensure you have the proper Xdebug configuration in your php.ini file. Will will need at a minimum the following settings:
xdebug.remote_autostart = 1
xdebug.remote_enable = 1
xdebug.idekey = PHPSTORM
xdebug.remote_host = 127.0.0.1

# Port 9000 is used by php-fpm. Use 9003 instead
xdebug.remote_port = 9003

Xdebug Port 9000 Conflicts

If you run into an issue running Xdebug via PHPStorm, or another IDE, when using the built-in PHP server on macOS, or Ubuntu, you might have a conflicting port 9000 with php-fpm.

You can check the 9000 port using the following command on:

sudo lsof -i tcp:9000

To check the port php-fpm occupies use the following command:

sudo lsof -i -n -P|grep php-fpm

Xdebug and php-fpm, or another service, might both be running on port 9000. The simple fix for this is to change the Xdebug port to 9003.

xdebug.remote_port = 9003

Then in PHPStorm set the Xdebug port to 9003 under Preferences | Languages & Frameworks | PHP | Debug.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.