Installing Xdebug on Homestead 7.0, PHP 7.2

Unhandled Perfection
Unhandled —Dev
Published in
2 min readFeb 5, 2018

As of recently it seems a fresh install of laravel homestead does not bring Xdebug setup out of the box. This seems to be confirmed from issue #800 on laravel’s github. https://github.com/laravel/homestead/issues/800

If you can’t wait for the new release here is the quick manual setup of xdebug.

Steps

Step 1) Download, unzip and compile Xdebug 2.6

sudo wget https://xdebug.org/files/xdebug-2.6.0.tgz
tar -xvzf xdebug-2.6.0.tgz
cd xdebug-2.6.0/
phpize
./configure
make

Step 2) Copy generated xdebug.so to proper location

sudo cp modules/xdebug.so /usr/lib/php/20151012

Step 3) Create Xdebug config file

sudo vim /etc/php/7.2/mods-available/xdebug.ini

with content

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

Step 4) Enable Xdebug

sudo ln -sf /etc/php/7.2/mods-available/xdebug.ini /etc/php/7.2/fpm/conf.d/20-xdebug.ini

Step 5) Restart php process manager

sudo service php7.2-fpm restart

Step 6) Cleanup

We can now remove the source directory and zip

cd ..
rm -rf xdebug-2.6.0*

Extra

The above steps will enable Xdebug for the browser interpreter only so don’t be alarmed if you don’t see Xdebug listed when running php from the command line.

>php -v
PHP 7.2.0-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 30 2017 13:58:33) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.2.0-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
with blackfire v1.18.0~linux-x64-non_zts72, https://blackfire.io, by SensioLabs

To also enable Xdebug for the CLI run this command:

sudo ln -sf /etc/php/7.2/mods-available/xdebug.ini \ 
/etc/php/7.2/cli/conf.d/20-xdebug.ini

and restart:

sudo service php7.2-fpm restart

You should now see Xdebug properly loaded:

> php -v
PHP 7.2.0-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 30 2017 13:58:33) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.2.0-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with blackfire v1.18.0~linux-x64-non_zts72, https://blackfire.io, by SensioLabs

Conclusion

Done.

--

--