Install Memcached on WHM/Cpanel Server
How to Install Memcached on WHM/Cpanel server
Speed is now of special importance in terms of SEO, website performance and reducing bounce rate. Website caching is one of the methods that can help improve site loading times for wordpress websites. Apart from using the caching plugins, it is important for websites to use at least one server-side caching. Object caching is a type of server-side caching that improves website loading times and helps provide a better user experience. It also helps utilize server resources efficiently. There are other types of server-side caching also like cdn caching, Opcode caching and page caching. However, in this post, we are going to discuss object caching with Memcached on WHM/ Cpanel server. There are two most popular options when it comes to object caching include Redis and Memcached.
What is object caching and what is Memcached?
Basically, caching means storing frequently accessed data or queries in a cache temporarily so that it can be served with subsequent requests. If your website does not have caching enabled the server will process the request, compile the page and then send it back to the browser whenever a client requests. For large websites, serving multiple pages in this manner can lead to slower page load times. Caching offers several benefits. It eases the load on your server, making it do less work and also serves responses to requests faster, accelerating your website. The server is able to handle more traffic when the burden is lower with caching compared to without having cache enabled.
We use plugins to cache website content like WP Rocket, W3TC, WP Fastest Cache, WP Super Cache and others like Autoptimize or Litespeed cache. There is a long list of caching plugins in the Wordpress plugin repository with installations in millions. If you have used W3TC, you must have seen the object caching, page caching and database caching sections in the plugin. The dropdown menus in these sections include Memcached and Redis. However, to enabled Memcached for object caching, you first need to install it on your server. Memcached is a type of persistent object caching and if you are experiencing fast traffic growth or expect it in near future, you must go for it since without persistent object caching, your site would soon grow slow. Memcached is a fast and powerful in memory data store that will reduce the load on your mysql database and improve loading speed as well as improve your site’s scalability and the ability to handle higher traffic. Memcached has remained a popular choice for object caching since long and is in use by Facebook.
How to install Memcached on WHM/Cpnael server?
Installing Memcached on your WHM/Cpanel server is easy and will take only some minutes. There are two parts to it. In the first part you install the required modules from PHP PECL and in the second you install the required Apache module mod_socache_memcache using EasyApache4.
Login to WHM as root user. Search for module installers which is available under Software. There are four options inside the Module Installer.
- PHP Extensions and Applications Package
- PHP PECL
- Perl Module
- Ruby Gem
We are concerned with the PHP PECL. PECL stands for PHP Extension Community Library. Click on manage before PHP PECL to enter the PHP PECL installer.
First select the php version you are running on your website. Inside the search box type memcache.
You will need to install both Memcache and Memcached. The installation process will last a few minutes. When the installation is complete, you will receive the message at the end that build process is completed successfully and extension memcahed enabled in php.ini like in the image below.
Now, search for Easyapache4 on the left inside the WHM. Here you will find a list of profoiles with available packages. Select to customize your currently installed packages. Click on Apache Modules and search for memcache. Install the apache module mod_socache_memcache.
Go to the PHP extensions segment in the same profile and search for memcache again. You will find the Memcached php extensions here for different php versions. You can enable the one you want based on your php version.
Now, go to your wordpress dashboard and install W3TC caching plugin. In your object cache and page cache sections, now you will find the option for Memcached active. Just select it and mark the difference. The configuration file for Memcached is located here on your server:
You can check this file using the vi command
Sudo vi /etc/sysconfig/Memcached
And edit it using the following command
You can change various configurations like max connections or cache size from here. To check the status of Memcached from your WHM, go to terminal and enter the following command:
Systemctl status Memcached.service
If Memcached has been successfully installed on your server, it will show its status as Active and running as in the image below.
Some other commands for starting, stopping or restarting Memcached are as follows:
systemctl start memcachedsystemctl stop memcachedsystemctl restart memcached