Skip to content

Setting up CLAW Vagrant w Xdebug

Jared Whiklo edited this page Aug 22, 2019 · 4 revisions

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/

Information

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

Steps

  1. 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"
  1. Bring up vagrant to build the machine, (if you haven't already).

  2. Login to vagrant. By running vagrant ssh.

  3. Install xdebug (we don't currently, that could change)

    sudo apt-get install php-xdebug

  4. 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"
  1. Restart apache, sudo /etc/init.d/apache2 graceful

  2. 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.

  1. Exit vagrant

  2. Create a new PHPStorm "Project from existing files..."

  3. 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.

  4. Once the Project is ready, go to Project Preferences > Directories

    1. You'll see the directory you already added (/sw/var/www/drupal-8)
    2. Add Context Root and choice the source code directories (ie. /sw/var/DAM2/islandora)
    3. Repeat for all code your are replacing (I do islandora, islandora_collection and claw-jsonld)
    4. Click Apply to save.
  5. Go to the Project Preferences > Languages & Frameworks > PHP >

    1. Debug : Make sure Xdebug is on port 9000 (the default) and "Can accept external connections" is checked.
    2. Servers : Add a new server for Vagrant, mine has:
      1. Host => localhost
      2. Port => 8000
      3. Debugger => Xdebug
      4. ✔️ Use path mappings
      5. Project files:
        1. /sw/var/www/drupal-8 --> /var/www/html/drupal/web
        2. /sw/var/www/DAM2/islandora --> /home/ubuntu/claw_code/islandora
        3. /sw/var/www/DAM2/islandora_collection --> /home/ubuntu/claw_code/islandora_collection
        4. /sw/var/www/DAM2/claw-jsonld --> /home/ubuntu/claw_code/claw-jsonld
    3. Drupal : ✔️ Enable Drupal integration, path is /sw/var/www/drupal-8, version is 8
    4. Click OK to save
  6. Go to Run > Edit Configurations...

  7. Expand the Defaults and find PHP Web Application.

    1. Make sure the Server is the one you created before for Vagrant.
    2. Start URL is /
    3. Browser is whichever browser you use most, they each have a different way of enabling and disabling Xdebug. You choose.
  8. Click OK to save.

  9. You should be ready to go. The test in the source article worked for me and I hope it works for you.

Using XDebug with REST requests

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.

This is an archive. For new Tech Call notes, click here

⚠️ ARCHIVED Islandora Tech Calls

⚠️ ARCHIVED Islandora User Calls

Clone this wiki locally