Skip to content

Instantly share code, notes, and snippets.

@rmatil
Last active October 27, 2018 03:00
Show Gist options
  • Save rmatil/4bc690f3884638c427c9 to your computer and use it in GitHub Desktop.
Save rmatil/4bc690f3884638c427c9 to your computer and use it in GitHub Desktop.
Puphpet, Vagrant, PHPStorm and Xdebug

Setup Xdebug for PHPStorm on vagrant using PHP

Create Virtual Machine

Go to PUPHPET and create your VM. Check Install Xdebug on step 4 (Languages > PHP).

Configure Xdebug on the VM

First check that everything went right while provisioning your VM: Create a new file named info.php and put the following code in it:

#/usr/bin/php

<?php
    echo phpinfo();

Request this file through your browser and check that the section xdebug appears. Also locate the custom configuration file named zzzz_custom.ini in the section about Additional .ini files parsed (/etc/php5/fpm/conf.d/zzzz_custom.ini)

Then SSH into your VM using vagrant ssh. Navigate to the configuration file located above. Open it and add the following line in the section named Xdebug (update it, if it does already exist) with the IP address of the VM:

    xdebug.remote_host=<IP address of your VM>

Close the file and restart php by using sudo service php5-fpm restart. Reload info.php from before in your browser and check that the changes are applied.

Configure PHPStorm

Open your project in PHPStorm. Go to Settings > Language & Frameworks > PHP > Servers and add a new server configuration:

  • Host: Host of the VM (either hostname configured in /etc/hosts on the host machine (the one hosting your VM -> your computer) or its IP address
  • Port: The port on which the website is reachable (default port 80)
  • Debugger: Select Xdebug as debugger
  • Use path mappings: Check this box to specify the location of the source files on the VM. Select the entry named Project files and assign its first entry the path to the files on the VM (e.g. /var/www). Then also specify where the public directory is located (e.g. /var/www/web)

Apply settings and close. Goto Run > Edit Configurations and create a new entry PHP Web Application from the list shown when hitting the + sign on the top left corner. Select the server configured just before. Then save and close.

Debug your Application

Set some breakpoints in the code, then start a debug session on Run > Debug. Your browser will open a new tab with your application and ?XDEBUG_SESSION_START=12345 to the URL. As soon as a breakpoint is reached in the code PHPStorm will be shown automatically with the debug toolbar opened

@carltondickson
Copy link

carltondickson commented May 18, 2017

Thanks for "sudo service php5-fpm restart".

I had xdebug working fine via the command line and I would disable it every now and then by disabling it in " sudo nano /etc/php/5.6/mods-available/xdebug.ini". Wondering if I had it disabled at the point I did a vagrant up and php5-fpm picked up the fact I had turned it off, which, as I mentioned was addressed by doing the restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment