Installing memcache on linux and add to PHP

Here are the steps you will need to install memcache on linux:
These direction are from: Crazytoon.com site, go there to read more about memcache and what people have suggested in the comments on this topic

wget http://monkey.org/~provos/libevent-1.3e.tar.gz
tar zxpfv libevent*
cd libevent*
./configure
make install

Now let’s download the newest Memcached source (at time of writing this was 1.2.4)

wget http://www.danga.com/memcached/dist/memcached-1.2.4.tar.gz
tar zxpfv memcached*
cd memcached*
./configure
make install

Let’s add Memcached user to run daemon as since we don’t need it to run as root privileges.

adduser memcached

We will start the server to use 48 megs of ram (-m 48), listen on ip 10.0.0.2 (-l 10.0.0.2) and run on port 11211 (-p 11211) as user memcached (-u memcached)

./memcached -u memcached -d -m 48 -l 10.0.0.2 -p 11211

If you get the following error (which you will get if you are doing this under CentOS 64 bit):

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

You can fix this by simply doing this:

ln -s /usr/local/lib/libevent-1.3e.so.1 /lib64/

That is all there is to it. You can see if daemon is running by telneting to the port.

After this you still need to add the extension to your php.ini file which you can find it in: /usr/local/lib/php.ini  If for some reason the file is not there, you can copy it from your php5.XX source folder to that location.

To confirm the location of where you should place the php.ini file, you can do
# php -i |grep php.ini
Look for ‘Configuration File (php.ini) Path’ this will be followed by the location of the lib folder where you php.ini is expected to be.

In your php.ini file add the following line:

extension=memcache.so

I also recomment running this command:

pecl install memcache

Leave a reply

You must be logged in to post a comment.