Using Xdebug with Vagrant and PHPStorm

19 Jan 2019

Intro

I’m already aware that people use dockers these days, but I was dissatisfied with the performance on Mac. Even under Windows, many hacks and additional tools (docker-sync) are needed to work with Docker, and yet I wasn’t satisfied. For these reasons, I’m back at Vagrant and describe here how to debug with PhpStorm PHP applications that run in a (good old) Vagrant box.

Install xdebug

I’m using Ubuntu, Apache and PHP 7.2 vagrant box setup.

If you have already setup another Vagrant box, please install and configure xdebug with this commands:

# install the php xdebug extension
sudo apt-get install php-xdebug

# add the xdebug settings to php.ini
sudo su
echo 'xdebug.remote_port=9000' >> /etc/php/7.2/apache2/php.ini
echo 'xdebug.remote_enable=true' >> /etc/php/7.2/apache2/php.ini
echo 'xdebug.remote_connect_back=true' >> /etc/php/7.2/apache2/php.ini
echo 'xdebug.remote_autostart=on' >> /etc/php/7.2/apache2/php.ini
echo 'xdebug.remote_host=' >> /etc/php/7.2/apache2/php.ini
echo 'xdebug.max_nesting_level=1000' >> /etc/php/7.2/apache2/php.ini
echo 'xdebug.idekey=PHPSTORM' >> /etc/php/7.2/apache2/php.ini

# restart apache
sudo service apache2 restart

Start your vagrant machine with: vagrant up.

PhpStorm Configuration

image

image

image

Debugging

image