Friday, August 16, 2013

Configuring Aptana Studio 3, PHP, and Xdebug on Ubuntu (13.04)

There seems to be a decent amount of documentation regarding Xdebug and Aptana Studio 3 on Ubuntu 13.04, but I still found myself stumbling, and figured it would be nice to have documentation that is as clear and concise as possible.  As it took me two attempts to make everything happy, I may not remember everything perfectly, but I will try my best to recount what worked for me.

Prerequisites:
Aptana Studio 3 installed
PHP5 installed

Verifying xdebug is installed
Create a php file with a call to phpinfo(), bring it up in your web browser and look for this:
Make sure you see something about "with Xdebug v#.#.#, etc..."


Installing xdebug
xdebug provides a package for ubuntu.  Installing it as as simple as:

sudo aptitude install php5-xdebug
Once that has completed installing, verify (as shown above) that it worked. Configuring xdebug
locate xdebug.ini
You should see at least one of these files. I found two:
Use your preferred text editor to modify the .ini file located in the conf.d directory. Mine happened to be named 20-xdebug.ini (you may need to have root privileges to modify it) Paste this into that .ini file, after the first line:
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.remote_mode="req"
xdebug.remote_log="/etc/php5/xdebug.log"
xdebug.auto_trace=off
xdebug.default_enable=on

Save, and then restart apache
sudo service apache2 restart

That should be all of the configurations required for Xdebug.

Getting Aptana Studio 3 to play nicely with Xdebug
In Aptana Studio: Window > Preferences > Aptana Studio > Editors > PHP > Debug
Make sure that Xdebug is listening to port 9000 (you'll notice we set that port when we pasted the last chunk of code into the xdebug.ini file)

In that same preferences window, proceed to: General > Web Browser. Use an external browser.  I've had luck with Firefox.  Chromium doesn't like being opened with root access (I open Aptana with root privileges so I can write to my document root easily)
Go ahead and close that window.  Head over to: Run > Debug Configurations. Right-click PHP Web Page and select New.  Name it whatever you like, make sure Xdebug is the selected server debugger.  Then add PHP Server.  For the base URL, I used: http://localhost, and for the document root, I used: /var/www/ (since that's where my apache server looks to).
You're basically done!  All you need to do us click the debug button and chose your configuration!  Good luck, and happy debugging.