Install the Memcache PECL Extension

The easiest installation method for memcache is to use PECL’s ‘install’ command. This will grab the latest stable release, configure it with the default options, and add it to the server’s php.ini:

pecl install memcache

Un-installation is just as easy:

pecl uninstall memcache

Now add the extension so it will load

nano /etc/php.d/memcache.ini

Add the following

; Enable memcache extension module
extension=memcache.so

Restart apache

service httpd restart

The quick install method for memcache uses the default configuration options and should serve most users’ purposes. However, if you need more control over the installation options, you can manually install from source and add it flags as you need.

1. Download the source package via PECL:

cd /usr/local/src/
pecl download memcache

2. Unpack the tar and enter into the newly extracted directory (be sure to replace the X’s with your downloaded version):

tar -xvzf memcache-X.X.X.tgz
cd memcache-X.X.X

3. Configure and install:

/usr/local/bin/phpize
./configure –with-php-config=/usr/local/bin/php-config

Note: If you are working on a server with cPanel, keep in mind that cPanel itself installs two versions of php:

/usr/bin/php
/usr/local/bin/php

For that reason you have to know which version your web server is actually using. Most of the time it is /usr/local/bin/php. It can get very confusing and can be different from server to server. If you are a ServInt customer, don’t hesistate to fill out a support ticket if you have any questions.

4. Verify the install:

Verify the installation by displaying all the installed PHP modules. See if memcache is listed:

php -m
memcache
Problems with manual installation

The “make install” should load the module into your server’s extension directory automatically. However, if you do not see memcache listed in a “php -m”, you will need to add the module manually.

1. First, verify the location of your server’s extensions directory:

grep extension_dir /usr/local/lib/php.ini

It should return something similar to the following:

extension_dir = “/usr/local/lib/php/extensions/no-debug-non-zts-20060613″

2. Next, copy the memcache module into that directory (be sure to replace the path with the one found on your server):

cp modules/memcache.so /usr/local/lib/php/extensions/no-debug-non-zts-20060613

3. Finally, add the module to your php.ini:

echo ‘extension=memcache.so’ >> /usr/local/lib/php.ini
Final Thoughts

It used to be a common issue that the quick ‘install’ method could not be used for servers where the /tmp partition was mounted “noexec”. The problem was that the “configure” process could not execute because the PECL client downloaded the module into in /tmp. When /tmp is mounted “noexec”, servers cannot execute scripts from /tmp.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.