palantirnet/devkit

XDebug

Closed this issue · 5 comments

becw commented

Is XDebug installed on the drupalbox? If so, how do you connect to it? Are there still performance issues associated with running Composer with XDebug enabled, or is there a workaround for that now?

I think @patrickfweston has worked on this on individual boxes, so if there are questions about our specific usage with Drupal, he will be a good resource for this issue.

The motivation to get xdebug working is that it's a much more efficient way of debugging than we currently have. Right now, debugging requires printing variables and arrays in code, refreshing the page, and seeing the values on the page.

I have not run into composer being slow with xdebug, but the usual warning does appear. Maybe I'm just used to composer being slow? Here's a handy link: https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer

The steps are a little complicated:

  • Install some necessary php development things:

    • sudo apt-get install php5-dev php-pear php5-xdebug
  • Pear had a broken symlink that was causing installation to fail for me. I deleted it and then when it installs xdebug, it recreates a working symlink so do that:

    • rm -rf /usr/share/php/doc/
  • Install xdebug:

    • sudo pecl install xdebug
  • There's a line at the end of the text it spits out after you install that says: You should add "zend_extension=/usr/lib/php5/20131226/xdebug.so" to php.ini so do that:

    • sudo vi /etc/php5/apache2/php.ini
    • I added the above line to the end of the ini file:
      • zend_extension=/usr/lib/php5/20131226/xdebug.so
  • Edit the xdebug config to work with PHPStorm: sudo vi /etc/php5/apache2/conf.d/20-xdebug.ini

  • Add:

    ; XDebug Profilers
    xdebug.remote_enable = true
    xdebug.remote_connect_back = 1
    xdebug.remote_autostart = 1
    
  • Restart apache: sudo service apache2 restart

  • You should now be able to set a breakpoint somewhere in your Drupal code and it'll catch in PHPStorm. For example, you can add it to the index.php file in the root.

I did this earlier and it worked, but Matt pointed out the "sudo pecl install" step is redundant.

Second, the step for enabling the extension in php.ini is not needed, the conf.d/20-xdebug.ini file enables the extension. You can still add the variables in this xdebug.ini file.

Cool! Glad it worked out for someone else as well. I didn't document as I went, so I could see there being redundant steps. Thanks for trying it out!

This has been added #36. We should be cutting 0.2.0 box shortly.

becw commented

My PHPStorm wasn't automatically connecting. Things I had to do:

  • Under Run > Edit Configurations, I made a new "PHP Remote Debug" configuration, use server, click "...", check the "Use path mappings" box, then map the "web" directory to "/var/www/MYPROJECT.local/web"
  • And then click the "phone" icon ("Listen for PHP Debug Connections") in the PHPStorm toolbar.