Debugging Laravel Homestead Applications with PHPStorm
Debugging PHP applications can be anything but easy. If you have, in the past, like me, found yourself resorting to echo, print_r and var_dump and find yourself using PHPStorm, then this article is for you.
Homestead comes with xdebug pre-installed. Visit the official xdebug docs if you don’t have it installed.
Verify that xdebug is installed and loaded
SSH into your virtual machine (VM) and run the line below
Confirm that xdebug is listed under [PHP Modules]
Confirm that Xdebug is listed under [Zend Modules]
Edit xdebug.ini file in conf.d directory. Run the following command from your virtual machine (VM) replacing [version] with your PHP version.
Example: cd /etc/php/php7.0/fpm/conf.d
To determine your PHP version, you can run the command below
Add the following lines to 20-xdebug.ini in the conf.d directory to enable xdebug and allow remote connections
zend_extension = xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
Restart the server. Replace [version] with your PHP version.
sudo service php[version]-fpm restart
Example: sudo service php7.0-fpm restart
Open PHPStorm -> Preferences -> PHP
Select the language level (Mine is PHP7)
Click the … (pointed to by yellow arrow) to open a dialog for adding a new interpreter
Click + in the upper left corner of the dialog and select Remote from the dropdown
Select Vagrant in the resulting dialog window and using the … option specify the path to your local Homestead. It’s usually
where [name] is the name of your home directory
NB: The Vagrant host url will be autopopulated after step (e) above
Open PHPStorm -> Preferences -> PHP -> Servers
Click + to add a new server (the server PHPStorm will use for debugging). Be sure to map your project to the corresponding directory on the remote (virtual machine) server. Remote path is usually
Install xdebug helper extension from chrome dev tools
Click the xdebug icon and select Debug
From PHPStorm menu select Run -> Start Listening for PHP Debug Connections
Set a breakpoint anywhere in your codebase
Reload the app from the browser and observe as PHPStorm starts a new debug session