Here is a complete guide for installing and configuring Memcached and Redis on cPanel running AlmaLinux 9 or CloudLinux 9, tailored for server optimization and performance enhancement.
๐ง Step 1: Enable EPEL Repository
yum install epel-release -y
This allows access to additional packages like Redis and Memcached not available in the base repos.
๐ Step 2: Install and Configure Redis
yum install redis -y
Start and Enable Redis
systemctl start redis
systemctl enable redis
Check Redis Status
systemctl status redis
You should see
Active: active (running)if Redis is working properly.
Benchmark Redis
Optional, but useful for a quick performance test:
redis-benchmark -q -n 1000
๐พ Step 3: Install Memcached
yum install memcached -y
Start Memcached
systemctl start memcached
systemctl enable memcached
Check Memcached Status
systemctl status memcached
You should see
Active: active (running)if Memcached is working.
โ๏ธ Step 4: Configure Memcached
Edit the configuration file:
nano /etc/sysconfig/memcached
Replace or confirm the following values:
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1 -U 0"
Explanation:
-l 127.0.0.1restricts Memcached to localhost (secure).-U 0disables UDP (recommended for security).- Adjust
CACHESIZEdepending on available RAM.
Restart Memcached to apply changes:
systemctl restart memcached
๐ Notes for cPanel Servers
- These services do not interfere with cPanel or WHM.
- For PHP-based applications (e.g., WordPress, Magento), make sure to install corresponding PHP extensions:
yum install ea-phpXX-php-pecl-redis ea-phpXX-php-pecl-memcachedReplaceXXwith your desired PHP version (e.g.,81).
You can verify extensions are loaded using:
php -m | grep -E 'redis|memcached'
โ Final Checklist
| Task | Status |
|---|---|
| EPEL installed | โ |
| Redis installed & running | โ |
| Memcached installed & running | โ |
| Memcached config updated | โ |
| PHP extensions installed | โ |
