This article will guide you on how to set up and configure Memcached on cPanel-WHM (RHEL 6/7 or CentOS 6/7).
Add EasyApache4 (EA4) Experimental Repository in order to install Memcached. Unfortunately, both Memcached and Memcache RPMs are still in an experimental repo on cPanel-WHM.
So it might not be suitable for a shared hosting environment. Additionally, the Memcached and Memcache PHP extensions in cPanel-WHM are only available for PHP 5.4, PHP 5.5., PHP 5.6, PHP 7.0, and PHP 7.1.
So, both Memcached and Memcache since 2016 are not yet available for cPanel-WHM PHP 7.2, PHP 7.3, and upcoming PHP 7.4.
However, if you use cPanel-WHM on your own cloud server or dedicated server, you might be interested in trying to use Memcached as a database caching for your site.
Prerequisite
A WHM server with root access to connect the terminal
Implementation
1. Add EasyApache4 Experimental Repository
We need to add the EA4 experimental repo to CentOS 7 system
$ yum install ea4-experimental -y |
2. Install Memcached Daemon
To install Memcached daemon on the system run the following command in the terminal
$ yum install ea-memcached -y |
3. Install Memcached and Memcache PHP Extensions
Install Memcached and Memcache PHP Extensions for PHP 5.4 – PHP 7.1.
$ yum install ea-php54-php-memcache ea-php54-php-memcached ea-php55-php-memcache ea-php55-php-memcached ea-php56-php-memcache ea-php56-php-memcached ea-php70-php-memcache ea-php70-php-memcached ea-php71-php-memcache ea-php71-php-memcached -y |
4. Configuring Memcached
We can customize the Memcached configuration in order to get the best performance for the cPanel-WHM server.
CACHE SIZE is a maximum amount of memory allocation that will be consumed by Memcached for object storage. While MAXCONN is the maximum number of simultaneous connections allowed by Memcached.
NOTE: Default Value for MAXCONN is 1024 and CACHESIZE 64
$ nano /etc/sysconfig/memcached ====== Edit the following lines then save and exit the file ======= PORT=”11211″USER=”memcached”MAXCONN=”2048″CACHESIZE=”256″OPTIONS=”-l 127.0.0.1,::1″ |
5. Edit .ini Configuration File for Memcache and Memcached
Finally, we must edit both memcache.ini and memcached.ini in order to enable this PHP extension.
Depending on the PHP version the locations of memcache.ini and memcached.ini files will be changed.
Note: we should uncomment session.save_handler and session.save_path.
$ nano /opt/cpanel/ea-php71/root/etc/php.d/memcache.ini $ nano /opt/cpanel/ea-php71/root/etc/php.d/memcached.ini $ nano /opt/cpanel/ea-php70/root/etc/php.d/memcache.ini $ nano /opt/cpanel/ea-php70/root/etc/php.d/memcached.ini $ nano /opt/cpanel/ea-php56/root/etc/php.d/memcache.ini $ nano /opt/cpanel/ea-php56/root/etc/php.d/memcached.ini $ nano /opt/cpanel/ea-php55/root/etc/php.d/memcache.ini $ nano /opt/cpanel/ea-php55/root/etc/php.d/memcached.ini $ nano /opt/cpanel/ea-php54/root/etc/php.d/memcache.ini $ nano /opt/cpanel/ea-php54/root/etc/php.d/memcached.ini ===== Uncomment the following lines ===== session.save_handler = “memcache” session.save_path = “tcp://localhost:11211” |
6. Restart Services
Restart the following services
$ service memcached restart $ chkconfig memcached on $ service httpd restart |