Installing Memcached or LSMCD and PHP Memcached Extention
To use object cache, you can install Memcached, or LiteSpeed's version of Memcached, LSMCD. To work with Memcached or LSMCD memory cache daemon, you will also need to enable the php memcached extention. This wiki will explain how to install/verify Memcached or LSMCD daemon, and also how to install/verify PHP PECL Memcached extention for your environment.
Install Memory Cache Daemon Memcached or LSMCD
Install LiteSpeed Memcached
LSMCD is a high-performance, distributed caching system with file-backed shared memory. It's generic in nature, but was originally intended for use in speeding up dynamic web applications by alleviating database load. It is designed as a drop-in replacement for Memcached, however we also have a few features that Memcached does not: High Availability and persistence of data. High Availability means that if one or more of your servers goes down, your data can still be accessed and updated as though it was still up. Persistence of data means that there is no need for a database backend. Whatever you put in LSMCD stays in LSMCD unless you say otherwise.
To install LiteSpeed Memcached, please see Compiling/Installing LSMCD.
Install Memcached
for Centos7
yum install memcached -y systemctl start memcached systemctl enable memcached
For Ubuntu/Debian
apt-get install memcached systemctl start memcached systemctl enable memcached
Verify Memcached or LSMCD Daemon
telnet 127.0.0.1 11211 stats
Install PHP Extension Memcached
For Plesk Centos7:
PHP7.0/7.1/7.2
yum install -y make plesk-php70-devel plesk-php71-develgcc plesk-php72-devel glibc-devel libmemcached-devel zlib-devel /opt/plesk/php/7.0/bin/pecl install memcached /opt/plesk/php/7.1/bin/pecl install memcached /opt/plesk/php/7.2/bin/pecl install memcached echo "extension=memcached.so" > /opt/plesk/php/7.0/etc/php.d/memcached.ini echo "extension=memcached.so" > /opt/plesk/php/7.1/etc/php.d/memcached.ini echo "extension=memcached.so" > /opt/plesk/php/7.2/etc/php.d/memcached.ini plesk bin php_handler --reread
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.
PHP5.6
yum install -y make plesk-php56-devel gcc glibc-devel libmemcached-devel zlib-devel /opt/plesk/php/5.6/bin/pecl install memcached-2.2.0 echo "extension=memcached.so" > /opt/plesk/php/5.6/etc/php.d/memcached.ini plesk bin php_handler --reread
And then graceful restart LSWS.
For Native LSWS Environment
PHP memcached packages are pecl packages and named lsphpxx-pecl-memcached
for CentOSs or lsphpxx-memcached
for Debian and Ubuntu in LiteSpeed Repo.
For Centos:
yum install lsphp56-pecl-memcached lsphp70-pecl-memcached lsphp71-pecl-memcached lsphp72-pecl-memcached lsphp73-pecl-memcached lsphp74-pecl-memcached
For Debian and Ubuntu:
apt-get install lsphp70-memcached lsphp71-memcached lsphp72-memcached lsphp73-memcached lsphp74-memcached
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.
For cPanel:
Centos
PHP7.0/7.1/7.2
yum install -y libmemcached-devel /opt/cpanel/ea-php70/root/usr/bin/pecl install memcached /opt/cpanel/ea-php71/root/usr/bin/pecl install memcached /opt/cpanel/ea-php72/root/usr/bin/pecl install memcached echo "extension=memcached.so" > /opt/cpanel/ea-php70/root/etc/php.d/20-memcached.ini echo "extension=memcached.so" > /opt/cpanel/ea-php71/root/etc/php.d/20-memcached.ini echo "extension=memcached.so" > /opt/cpanel/ea-php72/root/etc/php.d/20-memcached.ini
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.
PHP5.6
yum install -y libmemcached-devel /opt/cpanel/ea-php56/root/usr/bin/pecl install memcached-2.2.0 echo "extension=memcached.so" > /opt/cpanel/ea-php56/root/etc/php.d/20-memcached.ini
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.
Troubleshooting:
If installation returns error messages:
checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located ERROR: `/root/tmp/pear/memcached/configure --with-php-config=/opt/cpanel/ea-php71/root/usr/bin/php-config --with-libmemcached-dir=no' failed
Please install libmemcached and the memcached extension by compiling from source code (replace php71 with your php version):
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar zxvf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18 ./configure --prefix=/usr/local/libmemcached # if above failed with error related to SASL , please run "yum install cyrus-sasl*" and run: (without #) # ./configure --prefix=/usr/local/libmemcached --enable-sasl make make install wget http://pecl.php.net/get/memcached-3.0.4.tgz tar zxvf memcached-3.0.4.tgz cd memcached-3.0.4 /opt/cpanel/ea-php71/root/usr/bin/phpize ./configure --with-php-config=/opt/cpanel/ea-php71/root/usr/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl # if above failed with error related to SASL , please run "yum install cyrus-sasl*" and run: (without #) # ./configure --with-php-config=/opt/cpanel/ea-php71/root/usr/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-sasl make make install echo "memcached.so" > /opt/cpanel/ea-php71/root/etc/php.ini
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.
If you have further issues installing the extension on cPanel, please contact cPanel support.
CloudLinux
yum install ea-phpXX-php-memcached
Change XX
to PHP version number , as php70, php71…etc
Direct Admin
PHP7.0/7.1/7.2
yum install -y libmemcached-devel /usr/local/php70/bin/pecl install memcached /usr/local/php71/bin/pecl install memcached /usr/local/php72/bin/pecl install memcached echo "extension=memcached.so" > /usr/local/php70/lib/php.conf.d/20-memcached.ini echo "extension=memcached.so" > /usr/local/php71/lib/php.conf.d/20-memcached.ini echo "extension=memcached.so" > /usr/local/php72/lib/php.conf.d/20-memcached.ini
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.
PHP5.6
yum install -y libmemcached-devel /usr/local/php70/bin/pecl install memcached-2.2.0 echo "extension=memcached.so" > /usr/local/php56/lib/php.conf.d/20-memcached.ini
And then graceful restart LSWS and restart detached lsphp by killall lsphp
or pkill lsphp
.