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: https://xdebug.org/docs/install
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: 192.168.10.10. 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!

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

Communian – GO LIVE

In one of our previous blog posts we have announced Communian – an event platform for local communities, that will allow you to find interesting

Communian – COMING SOON

Update: We have launched communian.com on 19th November and we would like to invite you to check it out by registering. Find local communities of your

Leave a Reply

avatar
  Subscribe  
Notify of