Wednesday, January 7, 2009

How to Install Memcached with XAMPP and PHP4

resource links: http://www.freshblurbs.com/install-pecl-memcache-xampp-and-php4


this helps me a lot in my web development stuffs. awesome.


XAMPP is an absolutely wonderful, packaged, self-contained distribution of apache, mysql, php and tons of hard-to-install php extensions. Not only does it make sysadmin's life easier, by solving 99.9% of LAMP problems out-of-the-box, but it also allows PHP-vendors to create packaged distributions of complex systems.


However, even with a long list of packaged extensions, obviously there may be a need to install an additional one. PECL Memcache client of memcached distributed cache server, is a very probable candidate for high-load systems.


Unfortunately, PECL is broken in a vanilla XAMPP installation with php4. Typically you won't be able to use "pecl" directly and when you try to install manually with phpize you will get an error like:

" PHP Warning: Unknown(): Unable to load dynamic library '/opt/lampp/lib/php/extensions/no-debug-non-zts-20020429/memcache.so' - /opt/lampp/lib/php/extensions/no-debug-non-zts-20020429/memcache.so: undefined symbol: OnUpdateLong in Unknown on line 0"



Below is step-by-step guide of how to install a PECL extension (Memcache in this case) in the latest XAMPP:



  1. make sure you uninstall all and any PHP installations you may have had before along with PECL and PEAR
  2. Download and install XAMPP 1.6.1
  3. Add /opt/lampp/bin to your PATH
  4. Download and install XAMPP Development Package
    caution: it will overwrite any configuration changes you may have made previously
  5. backup /opt/lampp/include directory to /opt/lampp/include-bak. This directory
    is part of XAMPP-DEV but seems to be broken vis-a-vis PECL
  6. Download source distribution of the PHP corresponding to your XAMPP installation
    (for 1.6.1 it is PHP 4.6.4) and put it under "include" older so that the root of the
    php source distribution is /opt/lampp/include/php (rename the php-4.6.4 directory
    to php after unpacking).
  7. Run "./configure" and "make" on that php source.
    Caution: Do NOT run "make install"!!!
  8. Download memcache-2.1.2 anywhere

  9. # cd memcache-2.1.2
  10. # phpize
  11. # ./configure
  12. # make
  13. # make install
  14. Edit /opt/lampp/etc/php.ini and add a line:
    extension="memcache.so"

      Enjoy


memcache is just a client-side of the whole cache thing. You need to install server, as well, to do anything useful. The server (called memcached, as in memcache-daemon) requires libevent dynamic library. There is a small pitfall in instaling libevent. The installation itself is a straightforward "configure, make, make install" but once you install libevent and memcached, you may not be able to run memcached and get the following error, instead:


"memcached: error while loading shared libraries: libevent-1.1.so.1:cannot open shared object file: No such file or directory"


This is because memcached was not able to find the library location. Run memcached with:



$ LD_DEBUG=libs memcached -v

to see where is it looking for the libraries and install libevent there.


I had to run libevent configure as:


./configure --prefix=/usr

to fix this problem. You will need to uninstall/recompile/reinstall memcached if you reinstall libevent.


cheers

No comments:

Most Viewed