When working with PHPStorm and VVV (VaryingVagrantVagrants) in my development environment the integration and activation of Xdebug is relatively seamless.

Xdebug 3 is now available it requires slightly different settings in the PHP ini files to work in PHPStorm. Another positive benefit of using Xdebug 3 is it’s now quicker when debugging too.

Starting with out of the box VVV and after running

vagrant ssh -c "switch_php_debugmod xdebug" 

I ran debug validation in PHPStorm and got this dialog

So, whilst PHPStorm can see the Xdebug configuration it’s not yet fully configured. As noted some Xdebug settings have changed between version 2 and version 3. See the Xdebug update guide for more details

Enabling Xdebug 3 with VVV

To enable Xdebug 3 in our VVV / PHPStorm installation we need to add some settings to the php.ini file. VVV creates multiple ini files that are included into PHP as part of the php.ini file. We need to update only one particular file.

Manually – not recommended

If we were to do this manually to resolve the issue shown in the above screenshot, we would have to vagrant ssh into the virtual environment (from within our VVV folder) and manually edit and add these settings into /etc/php/7.2/fpm/conf.d/20-xdebug.ini

The site in my virtual machine uses PHP 7.2. Be sure to add these settings to the right one for your project

xdebug.client_host =192.168.50.1
xdebug.mode =debug

The IP address exposed by my VVV installation is 192.168.50.1. Yours will most likely be the same.

BUT! Adding these settings to /etc/php/7.2/fpm/conf.d/20-xdebug.ini manually would get overwritten on any vagrant provision.

Automatically including Xdebug 3 settings in php ini file

So, to have these settings included in the php.ini for each host and PHP version, in a terminal window inside your VVV folder (~/Sites/vvv/ for me) you can

Edit config/php-config/xdebug.ini

Add both these lines to the end:

xdebug.client_host =192.168.50.1
xdebug.mode =debug

Now, and don’t forget this step, be sure to set your Xdebug port to 9003 inside PHPStorm

And save the file and from your VVV folder inside your terminal window run the following command

vagrant reload --provision

No when you go back into PHPStorm to validate the installation you should see something like this:

Now I can debug my PHP code much easier and quicker.

Thank you for the featured image : Photo by Ben on Unsplash

Categories: WordPress

0 Comments

Leave a Reply

Avatar placeholder