-
Notifications
You must be signed in to change notification settings - Fork 71
Setting up CLAW Vagrant w Xdebug
This is using the current claw_vagrant as of 8296c2082070c84d079fc516594e7c57b7e368eb
I figured this out using this https://danemacmillan.com/how-to-configure-xdebug-in-phpstorm-through-vagrant/
You will need an exact copy of all your code inside and outside of Vagrant. You can probably share it all using synced folders if you'd like. But I setup just sharing the CLAW stuff I was going to be changing.
I have a MacBook Pro using Vagrant version 1.8.5 and Virtual Box 5.0.16 r105871.
I have Drupal 8.2.5 installed at /sw/var/www/drupal-8
on my laptop.
The rest of my CLAW code is under /sw/var/www/DAM2
, so:
/sw/var/www/DAM2/islandora
/sw/var/www/DAM2/islandora_collection
/sw/var/www/DAM2/claw-jsonld
...
Note: You can use XDebug with REST requests
-
Edit your Vagrantfile to add a synced_folder to include your live code. I added one new
synced_folder
below.So inside vagrant
/home/ubuntu/claw_code
maps to the directory under which all my CLAW code is.
# Setup the shared folder
home_dir = "/home/ubuntu"
config.vm.synced_folder ".", home_dir + "/islandora"
config.vm.synced_folder "/sw/var/www/DAM2", home_dir + "/claw_code"
-
Bring up vagrant to build the machine, (if you haven't already).
-
Login to vagrant. By running
vagrant ssh
. -
Install xdebug (we don't currently, that could change)
sudo apt-get install php-xdebug
-
To setup xdebug, edit the file
/etc/php/7.2/mods-available/xdebug.ini
it should look like this
zend_extension=xdebug.so
I changed mine to
[xdebug]
zend_extension=xdebug.so
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.remote_handler="dbgp"
-
Restart apache,
sudo /etc/init.d/apache2 graceful
-
Remap the islandora modules to the external ones, so you can edit in PHPStorm and see the results in vagrant
cd /var/www/html/drupal/web/modules/contrib
rm -rf islandora
rm -rf claw-jsonld
rm -rf islandora_collection/
ln -s /home/ubuntu/claw_code/islandora .
ln -s /home/ubuntu/claw_code/islandora_collection .
ln -s /home/ubuntu/claw_code/claw-jsonld .
This because both sets of code should be up-to-date you shouldn't need to uninstall/re-install the modules.
-
Exit vagrant
-
Create a new PHPStorm "Project from existing files..."
-
Choose your Drupal files (
/sw/var/www/drupal-8
in my example). This will have you pick the Context Root, which is the top directory. -
Once the Project is ready, go to Project Preferences > Directories
- You'll see the directory you already added (
/sw/var/www/drupal-8
) -
Add Context Root and choice the source code directories (ie.
/sw/var/DAM2/islandora
) - Repeat for all code your are replacing (I do islandora, islandora_collection and claw-jsonld)
- Click Apply to save.
- You'll see the directory you already added (
-
Go to the Project Preferences > Languages & Frameworks > PHP >
- Debug : Make sure Xdebug is on port 9000 (the default) and "Can accept external connections" is checked.
-
Servers : Add a new server for Vagrant, mine has:
- Host => localhost
- Port => 8000
- Debugger => Xdebug
- ✔️ Use path mappings
- Project files:
-
/sw/var/www/drupal-8
-->/var/www/html/drupal/web
-
/sw/var/www/DAM2/islandora
-->/home/ubuntu/claw_code/islandora
-
/sw/var/www/DAM2/islandora_collection
-->/home/ubuntu/claw_code/islandora_collection
-
/sw/var/www/DAM2/claw-jsonld
-->/home/ubuntu/claw_code/claw-jsonld
-
-
Drupal : ✔️ Enable Drupal integration, path is
/sw/var/www/drupal-8
, version is 8 - Click OK to save
-
Go to Run > Edit Configurations...
-
Expand the Defaults and find PHP Web Application.
- Make sure the Server is the one you created before for Vagrant.
- Start URL is
/
- Browser is whichever browser you use most, they each have a different way of enabling and disabling Xdebug. You choose.
-
Click OK to save.
-
You should be ready to go. The test in the source article worked for me and I hope it works for you.
To test how your code handles REST requests you can't simply use curl
as it won't send the necessary cookie to get XDebug to send your information. Luckily there is Postman. You must use the native application (not the browser app).
Then you can follow Postman's help to set a cookie like
XDEBUG_SESSION=PHPSTORM; path=/; domain=localhost;
Then you can include this cookie in your POST/PATCH/GET/PUT/DELETE/etc request and activate your breakpoints via XDebug.
You may be looking for the islandora-community wiki · new to islandora? · community calendar · interest groups · roadmap