How to set up debugging with PhpStorm and Homestead

Share on facebook
Share on twitter
Share on linkedin

Many php developers rely on var_dump (or it’s reincarnations in frameworks: debug(), dump(), dd(), etc) when debugging their code, and in most cases this is just fine, but not always good enough. When trying to solve complex problems or fix a stubborn bug, the great debugging capability of PhpStorm comes handy. It is quicker and more efficient to debug the code than to put dumps here and there.

Let’s take a look what is necessary to set up the debugging:

  • PhpStorm
  • Homestead (or any other Vagrant VM)
  • Xdebug extension

In the code examples please change paths according to your php version, I am using php 7.2.

Set up Xdebug

If you don’t have xdebug installed please find installation instructions here:
Open the Xdebug configuration with your favorite editor, in the example I’ll use nano:

Add/change the following settings in the xdebug configuration

Save the file, and restart php fpm:

If everything has been set up correctly, you should see the Xdebug extension installed and enabled in the output of the phpinfo():

Set up PhpStorm

In the menu choose Run/Edit Configurations, and add new PHP Web Page configuration:

Add a name to the configuration, and fill in the Start url and choose the browser and server from the dropdown options:

If the server dropdown is empty you’d need to add a new server. The if you are using the default Vagrant configuration the ip address of the server is: Check the Use path mapping checkbox, and set up the Absolute path of the project in the Homestead, the default location in homestead is /home/vagrant/code/project (I am using www instead of code)

That’s it! Clicking on the debug icon on the top right corner, the browser will open the project’s url and the debug session will start. You can put breakpoints by clicking on the left hand side of the code beside the line numbers:

Happy debugging!

0 0 vote
Article Rating

Subscribe to our newsletter

Be first to read new helpful post

Share this post with your friends

Share on linkedin
Share on xing
Share on twitter
Share on facebook

And the winners are …

As already announced we are going to launch 42workflows in the near future – a free open source package that will help you automate your

symphony process

Symfony Process with Laravel

Are you using ‘exec’, ‘passthru’, ‘shell_exec’ and ‘system’ php functions in your Laravel project? Taking care of security risks by yourself, as well as expecting

Notify of
Inline Feedbacks
View all comments