How to Install Memcached on AlmaLinux, RockyLinux, and CloudLinux Using WHM/cPanel

A complete guide on installing Memcached on AlmaLinux, RockyLinux, and CloudLinux using WHM/cPanel. This step-by-step process explains how to set up Memcached and configure the Memcached PHP extension for improved server performance.
Memcached logo with WHM/cPanel, AlmaLinux, RockyLinux, and CloudLinux logos, representing compatibility and caching installation.

Memcached is an in-memory caching system that helps speed up dynamic web applications by reducing database load. This guide will show you how to install Memcached on AlmaLinux 8 and 9, RockyLinux (latest versions), and CloudLinux 8 and 9 using WHM/cPanel.


Table of Contents

  1. Prerequisites
  2. Installing Memcached on AlmaLinux 8 and 9 with WHM/cPanel
  3. Installing Memcached on RockyLinux with WHM/cPanel
  4. Installing Memcached on CloudLinux 8 and 9 with WHM/cPanel
  5. Installing PHP Memcached Extension
  6. Verifying the Installation
  7. Common Issues and Troubleshooting
  8. Conclusion

1. Prerequisites

Before starting the installation, ensure you have:

  • WHM/cPanel installed and running.
  • Root access to your server.
  • PHP installed on your server.
  • EasyApache 4 installed for managing PHP extensions.

2. Installing Memcached on AlmaLinux 8 and 9 with WHM/cPanel

AlmaLinux, as a RHEL-based distribution, is fully compatible with WHM/cPanel.

Step 1: Log in to WHM

Go to https://your-server-ip:2087/ and log in with your root credentials.

Step 2: Install Memcached

First, update your system and install Memcached:

sudo dnf update -y
sudo dnf install memcached -y

Step 3: Configure Memcached

Edit the Memcached configuration file if needed:

sudo nano /etc/sysconfig/memcached

You can modify settings like memory usage, port, and user permissions here. Save your changes and exit the editor.

Step 4: Enable and Start Memcached

Enable and start Memcached to run it on boot:

sudo systemctl enable memcached
sudo systemctl start memcached

Step 5: Confirm Memcached is Running

Check if Memcached is running properly:

sudo systemctl status memcached

3. Installing Memcached on RockyLinux with WHM/cPanel

The process for installing Memcached on RockyLinux is similar to AlmaLinux.

Step 1: Log in to WHM

Access WHM by navigating to https://your-server-ip:2087/ and logging in with root access.

Step 2: Install Memcached

Update your system and install Memcached:

sudo dnf update -y
sudo dnf install memcached -y

Step 3: Configure Memcached

Edit the configuration file as needed:

sudo nano /etc/sysconfig/memcached

You can modify the memory usage, port, and user permissions to suit your needs. Save and exit once done.

Step 4: Enable and Start Memcached

Enable Memcached to start on boot and start the service:

sudo systemctl enable memcached
sudo systemctl start memcached

Step 5: Verify Memcached

Check the status of Memcached:

sudo systemctl status memcached

4. Installing Memcached on CloudLinux 8 and 9 with WHM/cPanel

CloudLinux includes some additional features such as CageFS and ALT-PHP, which need to be accounted for in the installation process.

Step 1: Log in to WHM

Log in to WHM at https://your-server-ip:2087/ using your root credentials.

Step 2: Install Memcached

Update your system and install Memcached:

sudo yum update -y
sudo yum install memcached -y

Step 3: Configure Memcached

Edit the configuration file as necessary:

sudo nano /etc/sysconfig/memcached

Adjust the settings for memory usage, port, and user permissions based on your server’s resources.

Step 4: Enable and Start Memcached

Enable Memcached to start at boot and run the service:

sudo systemctl enable memcached
sudo systemctl start memcached

Step 5: Install Memcached for ALT-PHP

If you’re using ALT-PHP on CloudLinux, you will need to install the Memcached PHP extension for each version of PHP in use:

for version in  alt-php{70,71,72,73,74,80,81}; do
    yum install $version-pecl-memcached -y
done

5. Installing PHP Memcached Extension

For PHP to work with Memcached, you need to install the Memcached PHP extension through EasyApache 4.

Step 1: Open EasyApache 4 in WHM

In your WHM dashboard, search for EasyApache 4 in the search bar and open it.

Step 2: Customize Your PHP Installation

Click on Customize next to your profile. Under PHP Extensions, search for Memcached.

Step 3: Install the Memcached Extension

Select the PHP versions you are using and enable the Memcached extension by checking the box.

Step 4: Provision and Restart

Click Review and then Provision. After the installation completes, restart Apache:

sudo systemctl restart httpd

6. Verifying the Installation

To verify that Memcached is working with PHP, follow these steps:

Step 1: Create a PHP Info File

Create a PHP file to check if Memcached is installed:

echo "<?php phpinfo();" | sudo tee /usr/local/apache/htdocs/info.php

Step 2: Open the PHP Info Page

Open your browser and navigate to http://your-server-ip/info.php. Look for Memcached in the PHP information.

Step 3: Remove the PHP Info File

After verification, remove the info.php file for security purposes:

sudo rm /usr/local/apache/htdocs/info.php

7. Common Issues and Troubleshooting

Issue 1: Memcached Not Appearing in PHP Info

Solution:

  • Make sure the Memcached extension is enabled for the correct PHP version in EasyApache 4.
  • Restart Apache after provisioning the extension.

Issue 2: Memcached Fails to Start

Solution:

  • Check the system logs using journalctl -xe to identify potential issues with the service.
  • Ensure that the correct port (default 11211) is available and not blocked by a firewall.

Issue 3: Memcached Not Working with ALT-PHP

Solution:

  • Install the Memcached PHP extension for each ALT-PHP version using the command provided in the CloudLinux section.
  • Ensure that CageFS has been updated by running cagefsctl --force-update.

8. Conclusion

Installing Memcached on AlmaLinux, RockyLinux, and CloudLinux using WHM/cPanel is a straightforward process. With EasyApache 4, setting up the Memcached PHP extension for different versions of PHP is simple, ensuring that your server is optimized for fast caching and improved performance. Always remember to verify your installation and check for any potential issues with troubleshooting steps provided.

Picture of admin

admin

Leave a Reply

Sign up for our Newsletter

Get the latest information on what is going on in the I.T. World.