Setting up Xdebug on Homestead 4.0 (PHP 7)

Published 11th January 2016

As Xdebug has been removed from the default Homestead box you now need to install it manually to be able to use it.

Once you have vagrant ssh-ed to your Homestead VM the first thing you need to do it download the latest compatible version of Xdebug (2.4.0RC3 at the time of writing) and build it:

cd /tmp 
wget http://xdebug.org/files/xdebug-2.4.0rc3.tgz
tar xvzf xdebug-2.4.0rc3.tgz
cd xdebug-2.4.0RC3/
phpize
./configure
make
sudo cp modules/xdebug.so /usr/lib/php/20151012/

You then need to the add your Xdebug config in /etc/php/mods-available/xdebug.ini:

; configuration for php xdebug module 
; priority=20
zend_extension=/usr/lib/php/20151012/xdebug.so xdebug.idekey="phpstorm"
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.max_nesting_level=300
xdebug.scream=0
xdebug.cli_color=1
xdebug.show_local_vars=1

Finally you need to add some symlinks so your new config file will be read by PHP:

sudo ln -s /etc/php/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini 
sudo ln -s /etc/php/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini

Finally restart PHP-FPM and you should be good to go:

sudo service php7.0-fpm restart

Most of this was based on the helpful Xdebug installation wizard.