How to Install and Configure Memcached and its PHP Extension

M

Microsuck

Guest
I just did an installation of Memcached and its PHP extension on my CentOS 5 64-bit server. I encountered a few issues that I will be explaining how I solved.

Hope you enjoy!

Prerequisites

You're going to need SSH (shell) access to your server for this as it requires a few installations.

Let's get some packages installed first. Below is the first batch of commands you need to run.

Code:
yum install libevent libevent-devel

Once that's finished:

Code:
yum install zlib zlib-devel

NOTE: zlib may already be installed for you. It wasn't for me, so I included it here.

Memcached

All right, now let's move onto the installation and configuration of Memcached.

First, you'll need to CD into the /usr/local/src/ directory using the command below:

Code:
cd /usr/local/src

Now, you need to visit this site:
http://code.google.com/p/memcached/downloads/list

Determine which version is the latest stable version (at this time, it's 1.4.13), then run the following command, REPLACING 1.4.13 WITH THE LATEST VERSION.

Code:
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz

Now, we're going to decompress the tarball we just downloaded.

Code:
tar xvzf memcached-1.4.13.tar.gz

At this time, we need to CD into the directory that tar just created.

Code:
cd memcached-1.4.13

The next step is configuring Memcached's makefile. There are some notes to go with this. Configuring can be as simple as running this:

Code:
./configure

Or, if you have a 64-bit machine:

Code:
./configure --enable-64bit

If your server has more than a single CPU, you can enable threading:

Code:
[FONT=Verdana]./configure --enable-threads[/FONT]


OR, if you have both a 64-bit machine AND more than a single CPU, you can enable both.

Code:
./configure --enable-64bit --enable-threads

Once you've run one of the above commands completely, we're going to make and install Memcached.

Code:
make && make install

Now, you simply need to activate Memcached by starting a server.

Code:
memcached -d -u nobody -m 512 -p 11211 127.0.0.1

Memcache PHP Extension

All right, at this point, you will be done for SOME PHP scripts, provided you have configured them to use Memcached.

BUT, for scripts like vBulletin, you need to install the Memcache PHP extension.

First thing you need to do here is go to this website:
http://pecl.php.net/package/memcache
and find the latest version of the extension. Beta or stable, they both seem to work fine for me. At this time, the latest is 3.0.6. So, if you're reading this and a later version comes out, just replace 3.0.6 with the most current version.

Code:
wget http://pecl.php.net/get/memcache-3.0.6.tgz

Now, let's decompress that.

Code:
tar -zxvf memcache-3.0.6.tgz

CD into that folder:

Code:
cd memcache-3.0.6

PHPIZE

Code:
phpize

Configure

Code:
./configure

Make

Code:
make

Make install

Code:
make install

Now, you'll need to edit php.ini and add this somewhere in it:

Code:
extension=memcache.so


Again from the shell, you'll need to run one more command to restart Apache:

Code:
service httpd restart



And you should be done! Post any questions here!
 

Members online

No members online now.

Top