andreliem

News for freelance developers

10/18/2016

Setting up PHP xdebug with Laravel, Vagrant, and PHPStorm

In case you find yourself banging your head against the wall trying to get XDebug setup for a Laravel project running on Vagrant + PHPStorm, here’s how I get it working.

This tutorial is based off this article below from sitepoint [http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/].

I found that it was missing a few smaller details for my own setup which I’ve included below.

The (paranthesese) refers to whether you are running the commands/instructions from the actual Vagrant server, the IDE, or your own local machine.

1) Install X-Debug

(Vagrant Server)

sudo apt-get update
sudo apt-get install php5-xdebug php5-dev

2) Update xdebug.ini

(Vagrant Server)

sudo vim /etc/php5/mods-available/xdebug.ini

add to bottom

xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.idekey = "vagrant"

3) Restart Server

(Vagrant Server)

sudo service php5-fpm restart

or just run this from your local machine

(Local Machine)

vagrant reload

4) Add Vagrant Server to IDE

(PHP Storm)

Settings->PHP->Servers->add

  • Update Name to anything
  • Host = Vagrant Machine IP
  • Use Path Mappings
  • Set File Paths
  • localmachine/path/to/root = /var/www
  • /localmachine/path/to/root/public = /var/www/public

I use the Scotch Box Vagrant setup which defaults the app root to /var/www/

5) Edit Debug Config

(PHP Storm)

  • Run->Edit Configurations
  • New PHP Web Application
  • Select your Server from step 4

Wrap Up

In theory if it all worked out, you should be able to run “debug” from PHPStorm and have it load up your browser with the right url params to connect debugging together.

Make the leap.
Subscribe to the newsletter
and learn how to become a freelance developer.