How to install Memcached on CentOS + Memcached PECL (Update : 2011.03.22)

By BXTra |

From previous HOW TO - http://www.bxtra.net/Articles/2010-04-27/How-install-Memcached-CentOS-DirectAdmin-installed-Memcached-PECL   I just think that I should note an update how to install Memcached so that I, myself, can follow the steps here and get the latest version. The steps are almost exactly to my previous Memcached PECL installed. Only a few changes to install an updated version.

Get Libevent which is require to install Memcached. Their homepage is here -> http://www.monkey.org/~provos/libevent/

wget http://monkey.org/~provos/libevent-2.0.10-stable.tar.gz
tar -xvf libevent-2.0.10-stable.tar.gz
cd libevent-2.0.10-stable
./configure;make;make install;

Then, get Memcached from http://memcached.org

wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
gunzip memcached-1.4.5.tar.gz
tar -xvf memcached-1.4.5.tar
cd memcached-1.4.5
./configure;make;make install;

For me, I got an error below when try to run memcached :

memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

So, I did steps below :

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

Once you're done with that, try run

memcached -d -u nobody -m 1024 127.0.0.1 -p 11211

This is not done yet, you need to let PHP knows to be able to use memcached.

wget http://launchpad.net/libmemcached/1.0/0.48/+download/libmemcached-0.48.tar.gz
tar xvfz libmemcached-0.48.tar.gz
cd libmemcached-0.48
./configure

You will see screen below :

Then, run

make && make install

Then install Memcached PECL with below command :

pecl install memcached

Once it's done, you may notice that the extension path is different to what we normally see. What you will see is :

/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626

But what most module for PHP 5.3 installed will compile into

/usr/local/lib/php/extensions/no-debug-non-zts-20090626

Therefore, make sure you get the right path for extension_dir Edit php.ini to have lines below : (Make sure the line "extension_dir" is there or you need a full path to memcached.so )

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20090626"
extension=memcached.so

Then, restart HTTP and check PHP Status.. You will see Memcached info as below:

In case you need to use Memcached as a session handler. (Not require) Then, you need to edit php.ini and set variable below :

session.save_handler=memcached
session.save_path="127.0.0.1:11211"

Now, you're done install Memcached on the server. However, you need to modify some code in your website script to make use of Memcached.

Server Information - Software
- CentOS 5.5
- DirectAdmin 1.38
- Apache 2.2.17
- PHP 5.3.6
- MySQL 5.5.9

Source :
- http://blog.ajohnstone.com/archives/installing-memcached/
- http://alexle.net/archives/275
- http://hasin.wordpress.com/2009/10/18/using-new-pecl-memcached-extension-for-storing-session-data/

[root@user libmemcached-1.0.5]# make && make install make all-am make[1]: Entering directory `/root/libmemcached-1.0.5' CXX libhashkit/libhashkit_libhashkit_la-algorithm.lo CXX libhashkit/libhashkit_libhashkit_la-behavior.lo CXX libhashkit/libhashkit_libhashkit_la-crc32.lo CXX libhashkit/libhashkit_libhashkit_la-digest.lo CXX libhashkit/libhashkit_libhashkit_la-fnv_32.lo CXX libhashkit/libhashkit_libhashkit_la-fnv_64.lo CXX libhashkit/libhashkit_libhashkit_la-function.lo CXX libhashkit/libhashkit_libhashkit_la-has.lo CXX libhashkit/libhashkit_libhashkit_la-hashkit.lo CXX libhashkit/libhashkit_libhashkit_la-jenkins.lo CXX libhashkit/libhashkit_libhashkit_la-ketama.lo CXX libhashkit/libhashkit_libhashkit_la-md5.lo CXX libhashkit/libhashkit_libhashkit_la-murmur.lo CXX libhashkit/libhashkit_libhashkit_la-one_at_a_time.lo CXX libhashkit/libhashkit_libhashkit_la-str_algorithm.lo CXX libhashkit/libhashkit_libhashkit_la-strerror.lo CXX libhashkit/libhashkit_libhashkit_la-nohsieh.lo CXXLD libhashkit/libhashkit.la CXX libmemcached/csl/libmemcached_libmemcached_la-context.lo CXX libmemcached/csl/libmemcached_libmemcached_la-parser.lo CXX libmemcached/csl/libmemcached_libmemcached_la-scanner.lo CXX libhashkit/libmemcached_libmemcached_la-algorithm.lo CXX libhashkit/libmemcached_libmemcached_la-behavior.lo CXX libhashkit/libmemcached_libmemcached_la-crc32.lo CXX libhashkit/libmemcached_libmemcached_la-digest.lo CXX libhashkit/libmemcached_libmemcached_la-fnv_32.lo CXX libhashkit/libmemcached_libmemcached_la-fnv_64.lo CXX libhashkit/libmemcached_libmemcached_la-function.lo CXX libhashkit/libmemcached_libmemcached_la-has.lo CXX libhashkit/libmemcached_libmemcached_la-hashkit.lo CXX libhashkit/libmemcached_libmemcached_la-jenkins.lo CXX libhashkit/libmemcached_libmemcached_la-ketama.lo CXX libhashkit/libmemcached_libmemcached_la-md5.lo CXX libhashkit/libmemcached_libmemcached_la-murmur.lo CXX libhashkit/libmemcached_libmemcached_la-one_at_a_time.lo CXX libhashkit/libmemcached_libmemcached_la-str_algorithm.lo CXX libhashkit/libmemcached_libmemcached_la-strerror.lo CXX libhashkit/libmemcached_libmemcached_la-nohsieh.lo CXX libmemcached/libmemcached_libmemcached_la-allocators.lo CXX libmemcached/libmemcached_libmemcached_la-analyze.lo CC libmemcached/libmemcached_libmemcached_la-array.lo CXX libmemcached/libmemcached_libmemcached_la-auto.lo libmemcached/auto.cc: In function 'memcached_return_t text_incr_decr(memcached_server_st*, bool, const char*, size_t, uint64_t, bool)': libmemcached/auto.cc:73: error: expected `)' before 'PRIu64' make[1]: *** [libmemcached/libmemcached_libmemcached_la-auto.lo] Error 1 make[1]: Leaving directory `/root/libmemcached-1.0.5' make: *** [all] Error 2
[root@tigapoin libmemcached-1.0.5]# libmemcached/auto.cc: In function 'memcached_return_t text_incr_decr(memcached_server_st*, bool, const char*, size_t, uint64_t, bool)': -bash: libmemcached/auto.cc:: No such file or directory [root@user libmemcached-1.0.5]# pecl install memcached downloading memcached-2.0.1.tgz ... Starting to download memcached-2.0.1.tgz (39,088 bytes) ..........done: 39,088 bytes 11 source files, building running: phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 building in /tmp/pear/install/pear-build-root96ENJx/memcached-2.0.1 running: /tmp/pear/install/memcached/configure checking for egrep... grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc 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 cc accepts -g... yes checking for cc option to accept ANSI C... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... i686-redhat-linux-gnu checking host system type... i686-redhat-linux-gnu checking target system type... i686-redhat-linux-gnu checking for PHP prefix... /usr checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib checking for PHP extension directory... /usr/lib/php/modules checking for PHP installed headers prefix... /usr/include/php checking if debug is enabled... no checking if zts is enabled... no checking for re2c... no configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. checking for gawk... gawk checking whether to enable memcached support... yes, shared checking for libmemcached... yes, shared checking whether to enable memcached session handler support... yes checking whether to enable memcached igbinary serializer support... no checking whether to enable memcached json serializer support... no checking whether to disable memcached sasl support... no checking for ZLIB... yes, shared checking for zlib location... /usr checking for session includes... /usr/include/php checking for memcached session support... enabled checking for memcached igbinary support... disabled checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir= to specify the prefix where libmemcached headers and library are located ERROR: `/tmp/pear/install/memcached/configure' failed
how to fix?

Got same error with new libmemcached 1.0.6 . Still, I don't have time to check it now cause I don't use memcached PECL anymore. Will check it again later.

The accepted answer was to place "#define __STDC_FORMAT_MACROS" at the top of the file. I did so for auto.cc and was able to compile that particular file

Well then. Apologies for the thread. Seems there was a similar issue in the gearmand module, and exporting the compiler environment variables to use gcc 4.4 works.

Just tested with version 1.0.7 and it works ok now.

Update : Well spoke too soon.. "./configure" was now compiled ok but after ran "make & make install" , below is the error I got :
CXX libhashkit/libmemcached_libmemcached_la-strerror.lo
CXX libhashkit/libmemcached_libmemcached_la-string.lo
CXX libhashkit/libmemcached_libmemcached_la-nohsieh.lo
CXX libmemcached/libmemcached_libmemcached_la-allocators.lo
CXX libmemcached/libmemcached_libmemcached_la-analyze.lo
CC libmemcached/libmemcached_libmemcached_la-array.lo
CXX libmemcached/libmemcached_libmemcached_la-auto.lo
libmemcached/auto.cc: In function 'memcached_return_t text_incr_decr(memcached_server_st*, bool, const char*, size_t, uint64_t, bool)':
libmemcached/auto.cc:73: error: expected `)' before 'PRIu64'
make[1]: *** [libmemcached/libmemcached_libmemcached_la-auto.lo] Error 1
make[1]: Leaving directory `/root/libmemcached-1.0.7'
make: *** [all] Error 2

Adam Listek

11 years 9 months ago

If it helps, the main problem with compiling libmemcached on CentOS 5.5 for me was the GCC version is too old. You can use the following to install an updated version which should enable you to compile it: yum install gcc44 gcc44-c++ libstdc++44-devel After the above installs, export the following environment variables to tell the configure script to use the newer GCC version (they install in parallel): export CC=/usr/bin/gcc44 export CXX=/usr/bin/g++44 -Adam

zilb was in /lib64 and autoconf was not able to locate, intalling zlib-devel gave it direct my giving pkgconfig.

Add new comment

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.