Saturday, May 22, 2010

Having Problems Installing xdebug on your eCommerce Test Server?

Quick description or summary of benefits of xdebug

If you are reading this, you have installed xdebug or are in the process of installing it because it is a useful web development debug tool for php based web applications.  I cannot sing the praises enough about the benefits.  Hear it, read the benefits of xdebug from a more authoritative source.


Our Problem & Troubleshooting may Help you Resolve yours

Just like you, we decided to employ xdebug to debug & resolve a nagging problem.  The following is a quick description of how we got to the point of wanting a debugger like xdebug, the installation issues and how we resolve them for our benefit.

How we got to wanting to use xdebug
 A customer who bought a Genesis crossbow from our Compound Crossbows Catalog wrote us that they liked our great price, better overall value shopping system, and would like to buy from us again when shopping for a range finder.  He wondered for himself and for our marketing strategy if we offer free shipping.  To him, we.responded that indeed we do  have free shipping in addition to our everyday Great $Price+Quick Shipping.  However, while we are 100% committed to better overall value for all of our customers, we do not use free shipping as a marketing gimmick whereby the other stores include double the price of shipping in the product price and then turn around touting free shipping.  Because we do pay the shippers (FedEx USPS,  or UPS) postage charges including insurance, and because our inexpensive prices translate to very thin profit margins, we have instructed our shipping calculator to algorithmically offer free shipping to customers when the price/weight combination of their cart items would put more money in the customer's pocket without putting us in the red.  We then told him that because of  this programmatic approach, rather than a blanket statement of free shipping, it is possible that the customer will be offered free ground shipping, or free 2 day expedited shipping or even free overnight expedited shipping depending on the price/weight combo mentioned before.  We then asked him to try it to see for himself even if he was not ready to get his range finder yet.  The customer called us two days later saying there was no free shipping no matter any priced item he added to the cart.  We reviewed our shopping cart shipping settings and configurations and they were properly configured—and there is no reason why free shipping should not be offered at the correct price/weight combos.  To cut the long story short, this is what prompted us to invoke a debugger to try to trace the steps and find out why the expected  free shipping offers were not appearing as expected.

Enter the xdebug Utility
With a quick Google search for php debugger we settled on xdebug as we judged it woild perfectly meet our need.  We then proceeded to download and install it.  The following is a summary of the installation problems and how we overcame it


Our xdebug Installation Problem and Resolution
Here is a quick spec of our test server where of course this utility is now installed. 

RedHat 5:
#cat /proc/version
Linux version 2.6.18-128.1.1.el5 (mockbuild@ls20-bc2-14.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Mon Jan 26 13:58:24 EST 2009

#uname -a
Linux lagos 2.6.18-128.1.1.el5 #1 SMP Mon Jan 26 13:58:24 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

1st problem - pecl is not there:
#pecl install xdebug

-bash: pecl: command not found
Because pecl not installed or not in the command path. most likely, pecl is not installed. pecl is part of the php development package. Development packages such as this including compilers should not be installed on production servers for security reasons. pecl and pear go together.  We went back to the net to install php dev package: Install php development package:

Install pear:

#wget "http://pear.php.net/go-pear"
After the download, verify that go-pear is in the current dir, then:

#php go-pear
Next add the bin directory to PATH and then confirm that pecl is also installed and available with pear with:
#pecl
which will give a list of usage commands and options if installation was correct.


2nd problem pecl not installing xdebug:
We attempted to install xdebug like this with the following output:

#pecl install xdebug
downloading xdebug-2.0.5.tgz ...
Starting to download xdebug-2.0.5.tgz (289,234 bytes)
.................done: 289,234 bytes
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 92160 bytes) in /var/PEAR/PEAR/PackageFile/v2/Validator.php on line 170
#

We at first thought to adjust the memory linit in php.ini.  And as we later found out adjusting memory limit in php.ini will not help because pecl does not use the php.ini config file to set memory limit

Also, instead of having to hack Validator.php (who knows what other problems that may bring?), we tried to install it (xdebug) this way with the following output:

#pecl download xdebug
downloading xdebug-2.0.5.tgz ...
Starting to download xdebug-2.0.5.tgz (289,234 bytes)
.................done: 289,234 bytes
File /xdebug-2.0.5.tgz downloaded

xdebug file we then next try to install it with pear since we have pear by now.  Note, like us, you should specify full filename this time instead of just the package name ie., xdebug-2.0.5.tgz instead of xdebug:

#pear install xdebug-2.0.5.tgz
67 source files, building
running: phpize
sh: phpize: command not found
ERROR: `phpize' failed

which brings up the
3rd problem: phpize not there!

If you get this error above, what you need, as we found out, is php-devel package which was not provided by RHN for our el5. However, we found out that the x87_64 arch from Cent OS was acceptable and you too should try it.  Here are some guiding steps:...

Do uname -a to get release version info
#uname -a
Linux hostname 2.6.18-128.1.1.el5 #1 SMP Mon Jan 26 13:58:24 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

Then see the version of the current php pckgs since the devel version must be at the same level to avoid problems.

#rpm -q --all | grep php
php-mysql-5.1.6-23.2.el5_3
php-pdo-5.1.6-23.2.el5_3
php-5.1.6-23.2.el5_3
php-cli-5.1.6-23.2.el5_3
php-ldap-5.1.6-23.2.el5_3
php-common-5.1.6-23.2.el5_3
Your output may be different from ours, but the idea is to verify the version level to be able to execute the next steps successfully.  Based on the above output we then got the equivalent version using

#wget "http://mirror.centos.org/centos/5/updates/x86_64/RPMS/php-devel-5.1.6-23.2.el5_3.x86_64.rpm"
--09:20:14-- http://mirror.centos.org/centos/5/updates/x86_64/RPMS/php-devel-5.1.6-23.2.el5_3.x86_64.rpm
Resolving mirror.centos.org... 66.109.26.212
Connecting to mirror.centos.org|66.109.26.212|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 514033 (502K) [application/x-rpm]
Saving to: `php-devel-5.1.6-23.2.el5_3.x86_64.rpm'

100%[==============================================================>] 514,033 68.2K/s in 6.8s

09:20:21 (74.4 KB/s) - `php-devel-5.1.6-23.2.el5_3.x86_64.rpm' saved [514033/514033]

Once you have the correct version, install it:
#rpm -ihv php-devel-5.1.6-23.2.el5_3.x86_64.rpm
warning: php-devel-5.1.6-23.2.el5_3.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:php-devel ########################################### [100%]


After the installation, we verify that it is okay as follows from the top level source directory of the module:

#/usr/bin/phpize

If the above commands displays a warning or a message, it can be ignored as we found out.

Now try to re-install xdebug (again) and verify the good news as it progresses to completion successfully:
#pear install xdebug-2.0.5.tgz
67 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20050922
Zend Extension Api No: 220051025
building in /var/tmp/pear-build-root/xdebug-2.0.5
running: /var/temp/xdebug/configure
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking whether gcc and cc understand -c and -o together... yes
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-redhat-linux-gnu
................Several output lines omitted................

Libraries have been installed in:
/var/tmp/pear-build-root/xdebug-2.0.5/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

..........................More output lines omitted...............
Build process completed successfully
Installing '/usr/lib64/php/modules/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.0.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=xdebug.so" to php.ini
 Congratulations for Problem Resolved if you see the last line
That's it. You're ready to use xdebug.  Well, almost ready.  Notice the last line. Very important. Add it to your php.ini to really complete the install and be ready to use it:.
extension=xdebug.so

Please see xdebug home for latest updates and configuration info.

PS: With xdebug, we quickly found our free shipping issue and fixed it.  It turned out that as soon as the shipping & handling charge was set to 0.0, the first expression after the loop was setting the shipping back to the original amount that was saved. Silly, eh?  It happens occasionally. 

No comments:

Post a Comment

Internet blogs