How to Setup Xdebug in Homestead and PHPStorm

Configure Xdebug in Laravel Homestead

The latest build of Laravel Homestead has Xdebug already installed, you just have to correctly configure it and make sure it is running and ready to accept connections. If you don’t have Homestead yet, you can follow the official documentation about installing it in your machine.

# for PHP 7 versions
sudo vim /etc/php/7.x/fpm/conf.d/20-xdebug.ini
# for PHP 8 versions
sudo vim /etc/php/8.x/fpm/conf.d/20-xdebug.ini
# for PHP 7 versions
sudo service php7.x-fpm restart
# for PHP 8 versions
sudo service php8.x-fpm restart
php -v
The example output after executing php -v in the homestead environment.
The example output after executing xon alias in the homestead environment.
he example output after executing xoff alias in the homestead environment.

Install Chrome Xdebug Plugin

Assuming you are using the chrome browser for development, installing the Xdebug helper chrome extension is recommended.

PHPStorm Configurations

To debug PHP applications in PHPStorm, PHP server settings and debug configuration are needed.

PHP Server Settings

  • Go to PHPStorm preferences / settings.
  • In the PHP Section, go to servers.
  • Add a PHP server and provide the server, host, and port. In the host field, set the IP or the local domain of the homestead and then use port 80 (since we want to debug routes for now).
An example PHP server settings for PHPStorm.
  • Lastly, click apply or ok.

Debug Configuration

  • To add debug configuration, click “Run”, and then “Edit configurations..”.
  • In the Run/Debug Configurations window, click the “+” and choose PHP Remote Debug.
  • Set the name, check the “Filter debug connection by IDE key” checkbox, select the server you just created previously, and provide the ide key configured from the Xdebug configuration of the homestead.
An example of debug configuration in PHPStorm.

Usage and Testing

At this point, you should be all set to debug any PHP or Laravel application. Let’s start debugging by selecting the debug configuration that we have just created as the run configuration and then make sure that PHPStorm is listening for debugging connection.

Running with debug configuration and listening for debugging connections.
The example of debug breakpoints in PHPStorm
Inspecting a variable during debugging mode in PHPStorm.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ariel Magbanua

Ariel Magbanua

I am a software engineer by day and writer by night. I write mostly about software development for both web and mobile.