Go to PUPHPET and create your VM. Check Install Xdebug on step 4 (Languages > PHP).
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.
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.
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
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.