Monday, November 7, 2011

Drupal - Code Driven Development

I think most of my sites have 2 versions...LOCAL and LIVE to allow testing of various changes as well as developing new themes and modules. Some sites have 3 versions, LOCAL, USER TEST, and LIVE.

I like having a local version so that I can polish it first. Also, I use tools like NetBeans for coding and debugging.

I use "Code driven development" for all my Drupal sites. Remember, the changes you are making through the GUI in your Drupal site are being saved to the database.  To use code-driven development, you need to get those changes out of the DB and into code.  This is where Features comes in.  My process:
  1. Develop code or theme; make your config changes in Drupal
  2. Export as much as possible using Features and Strongarm - This puts the DB changes into code
  3. Checkin the code to your version control system
  4. On the server - pull code from your repo
  5. Enable the various Features
Once you have your systems and procedures in place, this can actually be a time saver.  It's actually quite fun!!!! :)

Debugging PHP in NetBeans (in Ubuntu)



Here are the steps I used to setup PHP debugging in NetBeans (6.8 at the time of this writing) in Ubuntu 10.

sudo apt-get install php-pear
sudo apt-get install php5-dev
sudo apt-get install php5-xdebug



Edit your PHP INI settings
sudo nano /etc/php5/apache2/php.ini

Add the following lines under extensions:


zend_extension=/usr/lib/php5/the-folder/xdebug.so
xdebug.remote_enable=on


In my case it was ""/usr/lib/php5/20090626+lfs".  You will have to find the xdebug.so file in the correct folder.

Restart Apache
sudo /etc/init.d/apache2 restart


NetBeans PHP Debug Settings
  1. Goto tools->Options
  2. Select PHP
  3. On the General tab
  4. If this is your first time configuring xdebug, you may want to keep "Stop at First Line" checked.  this way when you start debugging you should know right away that your setup is correct. 
Start Debugging
  • Add some break points.
  • Right-click your project and select Debug