Tuesday, July 13, 2010

Installing Zend Debugger for Ubuntu

I am still seeing so many people using var_dump(). I think most of us spend more than 50% of our time debugging. There is no excuse for investing some time for a better debugging tool. This guide will show you how to configure Zend Debugger for Zend Studio under Ubuntu.

Requirements:
  • Zend Studio 7.x.x
  • Firefox with Zend Studio toolbar
Assumptions:
  • You are using Linux Ubuntu distribution. Other Linux distribution should be similar.
  • You must already have Zend Studio installed.
You need the ZendDebugger.so extension loaded in order to enable Zend Debugger. This PHP extension comes with Zend Studio.

Finding ZendDebugger.so
If Zend Studio is installed, you can locate ZendDebugger.so as follow:
  1. sudo updatedb
    Update the database of all the files and directories in our system. This command should be run by the cron job everyday. You may omit this step unless Zend Studio is newly installed.
  2. locate ZendDebugger.so
    Find the exact path to ZendDebugger.so
Expected results:
/home/user/Zend/ZendStudio-7.2.1/plugins/org.zend.php.debug.debugger.linux.x86_5.3.7.v20100625/resources/php5/ZendDebugger.so
/home/user/Zend/ZendStudio-7.2.1/plugins/org.zend.php.debug.debugger.linux.x86_5.3.7.v20100625/resources/php53/ZendDebugger.so
Load ZendDebugger.so extension
I do not recommend editing the php.ini file as we can easily create a mess in there. Instead, we should create a new configuration file under /etc/php5/conf.d directory. All configuration files end with ini under that directory will be loaded every time PHP execution is called. We can easily maintain our configuration that way:
sudo cat > /etc/php5/conf.d/zend_debugger.ini
Paste from command line (ctrl+shift+v):
zend_extension=/full/path/to/ZendDebugger.so
zend_debugger.allow_hosts=127.0.0.1, 192.168.0.1/16
zend_debugger.expose_remotely=always
done with ctrl+c.
zend_debugger.allow_hosts - which hosts allowed to debug, separated by comma.
zend_debugger.expose_remotely - telling the web browser that Zend Debugger is enable on this server.

If you are using PHP 5.3, you must use .../php53/ZendDebugger.so. Otherwise, use .../php5/ZendDebugger.so.


Restart apache server:
sudo service apaches restart
Hopefully, there is no error. Otherwise, check the path to your ZendDebugger.so or the version of ZendDebugger.so you are loading. Most of the problem occur there.

Confirm Zend Debugger is installed
Create a test page as follow:
cat > test.php
Paste from command line (ctrl+shift+v):
<?php
echo phpinfo();
done with ctrl+c.
If you see the following image, your Zend Debugger is successfully configured on your server. In my case, it's just my personal laptop.


Let's debug...
Open Firefox with Zend Studio toolbar, go to your website click on the Debug button as show below:



Enjoy! But please remember, It is twice as difficult to debug a program as to write it. Therefore, if you put all of your creativity and effort into writing the program, you are not smart enough to debug it.
Anonymous
Enhanced by Zemanta

No comments:

Post a Comment