Instructions to install Memcached for DirectAdmin


Well-known member
May 20, 2016
Currently, the Memcached module supports 2 versions and each of these versions will support different types of PHP:

php-memcached 3.x:
- Supports PHP 7.0 - 7.1.
- Requires libmemcached 1.x or higher.
- Optionally supports igbinary 2.0 or higher.
- Optionally supports msgpack 2.0 or higher.
php-memcached 2.x:
- Supports PHP 5.2 - 5.6.
- Requires libmemcached 0.44 or higher.
- Optionally supports igbinary 1.0 or higher.
- Optionally supports msgpack 0.5 or higher.
So to support PHP 7, you have to install Memcached 3 and vice versa, the necessary condition is that you have to have a library for Memcached, libmemcached.

This post will guide installation on Memcached Version 3.

Step 1: Download the memcached module and libmemcached at the following links:

memcached download:
libmemcached download:
Step 2: Install Libmemcached

gunzip libmemcached-1.0.18.tar.gz
tar -xvf libmemcached-1.0.18.tar
cd libmemcached-1.0.18
make && make install
Step 3: Install Memcached module

tar -xvzf memcached-3.0.4.tgz
cd memcached-3.0.4
make && make install
After installation is complete, you will see an attached message linking to the file not containing folder of memcached module as follows:

Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
Note that this link /usr/local/lib/php/extensions/no-debug-non-zts-20160303/ can be different from your link when you installed Memcached on your server. So, when you are installing, just copying the link that memcached generated for your server to replace with our link mentioned in this post.

Step 4: Configure PHP to accept the configuration of the memcached module
You use the following command to find the file php.ini

php -i | grep "php.ini"
Next, open the php.ini file and add to the end of the file the following directive:
extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20160303/"
Save and restart apache with the following command:

/etc/init.d/httpd restart
Now check using the command:
php -m | grep memcached
If the memcached text appears, congratulations, you have succeeded in compile the memcached module.

Step 5: Install memcached service
memcached service listen on port 11211, there are 2 ways to install it and here I use yum to make it easy to install

yum install memcached -y
/etc/init.d/memcached start
chkconfig memcached on
Verify that the memcached service is working with the following command:

netstat -nltp | grep 11211
If there is a tcp connection, it is successful to listen on this port.
Now if the source code is wordpress you can download the w3 total cache plugin to combine with the memcached methods to see a significant improvement in page load speed.

Step 6: Check if memcached works

Method 1:

In the directory containing the source code you create a file cache_test.php content as follows:
$mem = new Memcached();
$mem->addServer("", 11211);
$result = $mem->get("hello");
if ($result) {
echo $result;
} else {
echo "Not find the key, I will add now!";
$mem->set("hello", "I am data, I am saved in memcached.") or die("Can not save to memcached...");
Save and access your_domain/cache_test.php form for the first time, there will be no cache and the 2nd time onwards will have cache, if the content from the 2nd time onwards is "hello", "I am data, I am saved in memcached! ” then it will succeed.

Method 2:
You will use telnet command to check:

telnet localhost 11211
stats items
The result is as follows: saving key - values

STAT items: 2: number 1
STAT items: 2: age 106
STAT items: 2: evicted 0
STAT items: 2: evicted_nonzero 0
STAT items: 2: evicted_time 0
STAT items: 2: outofmemory 0
STAT items: 2: tailrepairs 0
STAT items: 2: reclaimed 0
STAT items: 2: expired_unfetched 0
STAT items: 2: evicted_unfetched 0
Clear cache and telnet exit with the following command, revisit the page, if the key - value values are recorded, it means that memcached module has worked with the memcached service, guys.

Good luck!
Older Threads

Latest Hosting OffersNew Reviews


Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.