Home / Blog / Remote Xdebuging a Vagrant box
Angel's picture
Angel Alvarado R.
Soft. and Data engineer.
23 Jan 2017
Xdebuging a Vagrant box

How to Use xdebug and vagrant


Our xdebug configuration in the Vagrant machine

From this article: Vagrant: A box with Drupal 7 simpleSAMLphp. We have xdebug installed in our Vagrant machine. 

Let's configure it. Connecting to the Vagrant Machine.

  1. $ cd vagrantrepo & vagrant ssh

Editing 'php.ini'. In the vagrant machine we'll edit 20-xdebug.ini since it is where Nginx is storing the xdebug settings

  1. sudo vi /etc/php5/fpm/conf.d/20-xdebug.ini
  1. zend_extension=xdebug.so
  2. xdebug.remote_enable = on
  3. xdebug.remote_connect_back = on
  4. xdebug.idekey = "vagrant"

Restarting Ngix

  1. sudo service php5-fpm restart

Debuging from SublimeText or PHPStorm: 

I don't want to dive into how to install and enable xdebug in SublimeText or PHPStorm. 

Follow the following tutorial for ST: webdevstudios.com

And this one for PHPStorm: https://confluence.jetbrains.com/

Tunneling into the remote server 

We have two "ways" to create the tunnel to the Vagrant machine. 

1.- Using the regular ssh command

  1. ssh -R 9000:localhost:9000 vagrant@; the password is 'vagrant' as usual.

2.- Using the vagrant ssh command

  1. vagrant ssh -- -R 9000:localhost:9000
  3. Don't forget to execute it from the Vagrant repo/folder.


We are absolute sure that the tunnel is stablished executing $ netstat -nlt | grep 9000. The output should look like this:

  1. tcp 0 0* LISTEN
  2. tcp6 0 0 ::1:9000 :::* LISTEN

If still the above output is blank. Try disabling the FireWall

  1. sudo ufw disable


Open FW only for the port 9000.