Instructions to install Memcached for DirectAdmin

MooseLucifer

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

Code:
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.
Code:
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:

Code:
memcached download: https://pecl.php.net/package/memcached
libmemcached download: https://launchpad.net/libmemcached/+download
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
wget https://pecl.php.net/get/memcached-3.0.4.tgz
Step 2: Install Libmemcached

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

Code:
tar -xvzf memcached-3.0.4.tgz
cd memcached-3.0.4
phpize
./configure
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:

Code:
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

Code:
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/memcached.so"
Save and restart apache with the following command:

Code:
/etc/init.d/httpd restart
Now check using the command:
Code:
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

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

Code:
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:
Code:
<?php
$mem = new Memcached();
$mem->addServer("127.0.0.1", 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:

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

Code:
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.

Code:
flush_all
quit
Good luck!
 
Older Threads
Recommended Threads

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

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.

Top