Every WordPress page load triggers dozens of MySQL database queries. Without object caching, those queries run every single time — even for identical requests. Memcached solves this by storing the results of expensive database queries in RAM, allowing WordPress to retrieve them in under a millisecond instead of hitting MySQL each time. This guide covers the complete setup of Memcached on DirectAdmin servers: installation, PHP extension configuration, WordPress object cache configuration, and performance verification.
What Memcached Does and When to Use It
Memcached is a distributed in-memory key-value store that acts as a caching layer between WordPress and MySQL. Instead of running a query like "get all posts in category X with their metadata", WordPress stores the result in Memcached RAM and retrieves it from memory on the next request — bypassing MySQL entirely.
Best use cases for Memcached on DirectAdmin:
- WordPress sites with high database query counts (WooCommerce, membership sites, forums)
- Servers where MySQL CPU usage is consistently above 30-40%
- Sites using page caching (Memcached handles object-level caching, page caches handle full-page caching — they complement each other)
- Multi-site WordPress installations
Memcached vs Redis: Both are in-memory caches. Redis supports data persistence (data survives restarts) and more data structures, making it better for session storage and advanced caching. Memcached is simpler, uses less RAM per cached object, and is often faster for pure object caching workloads. Choose Memcached if you already have it on your DirectAdmin server or prefer a lighter footprint; choose Redis if you need persistence or are already using it for sessions.
💡 None of these worked? Skip the guesswork.
Get Expert Help →Step 1: Install Memcached on DirectAdmin
DirectAdmin runs on CentOS, AlmaLinux, CloudLinux, or Debian/Ubuntu. Installation differs slightly by OS.
CentOS / AlmaLinux / CloudLinux
yum install -y memcached libmemcached libmemcached-devel
systemctl start memcached
systemctl enable memcached
systemctl status memcached
# Expected output includes: Active: active (running)
Debian / Ubuntu
apt-get update
apt-get install -y memcached libmemcached-tools
systemctl start memcached
systemctl enable memcached
On CentOS/AlmaLinux: /etc/sysconfig/memcached
On Debian/Ubuntu: /etc/memcached.conf
For CentOS/AlmaLinux (/etc/sysconfig/memcached):
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="256"
OPTIONS="-l 127.0.0.1"
For Debian/Ubuntu (/etc/memcached.conf):
-m 256
-l 127.0.0.1
-p 11211
Memory sizing guide:
- Low traffic WordPress (under 5,000 visits/day): 64-128 MB
- Medium traffic (5,000-50,000 visits/day): 256 MB
- High traffic (50,000+ visits/day or WooCommerce): 512 MB — 1 GB
Security note: Always bind Memcached to 127.0.0.1 (localhost), never to a public IP. Memcached has no built-in authentication and is a common DDoS amplification vector if exposed publicly.
systemctl restart memcached
cd /usr/local/directadmin/custombuild
./build versions | grep php
# Check current options for PHP 8.2 (or your version):
cat options.conf | grep memcache
./build php n
# or for a specific version:
./build php82_memcached
Manual Install via PECL or Package Manager
If CustomBuild does not cover your setup:
# Install php-memcached via yum (CloudLinux/cPanel-style repos):
yum install -y ea-php82-php-memcached
# Or via PECL:
pecl install memcached
# Enable the extension (add to php.ini or a conf.d file):
echo "extension=memcached.so" > /etc/php.d/memcached.ini
php -m | grep -i memcach
You should see memcached in the output.
php -r "var_dump(class_exists('Memcached'));"
# Expected: bool(true)
telnet 127.0.0.1 11211
# In the Memcached session:
stats
# You will see output with curr_connections, cmd_get, cmd_set, etc.
quit
Create a test file at /var/www/vhosts/yourdomain.com/httpdocs/memcache_test.php:
<?php
$m = new Memcached();
$m->addServer('127.0.0.1', 11211);
$m->set('test_key', 'memcached_working', 60);
$result = $m->get('test_key');
echo ($result === 'memcached_working') ? 'SUCCESS: Memcached is working' : 'FAILED: Memcached not responding';
?>
Access it via browser. Delete the file after testing — it should not be left on production.
memcached-tool 127.0.0.1:11211 stats
memcached-tool 127.0.0.1:11211 stats | grep -E "cmd_get|get_hits|get_misses"
After several page loads, the get_hits number should be climbing. Calculate hit rate:
Hit Rate = get_hits / (get_hits + get_misses) * 100
A healthy hit rate for WordPress object caching is above 80%. Low hit rates may indicate the cache is too small or keys are expiring too quickly.
memcached-tool 127.0.0.1:11211 stats | grep bytes
# curr_bytes: current memory in use
# limit_maxbytes: your configured limit
If curr_bytes approaches limit_maxbytes, increase Memcached's memory allocation.
With the Query Monitor plugin active, check the Database tab before and after Memcached. A well-configured object cache typically reduces database queries by 40-80% on repeat requests.
Step 7: DirectAdmin Multi-PHP Version Considerations
If you run multiple PHP versions on your DirectAdmin server (e.g., PHP 7.4 and PHP 8.2 for different domains), the Memcached extension must be installed for each PHP version your WordPress sites use.
# Check which PHP version each domain uses:
cat /usr/local/directadmin/data/users/username/domains/yourdomain.com.conf | grep php
# Build Memcached extension for additional PHP versions:
cd /usr/local/directadmin/custombuild
./build php74_memcached
./build php82_memcached
After building, restart PHP-FPM for each version:
systemctl restart php74-fpm
systemctl restart php82-fpm
Troubleshooting Common Memcached Issues on DirectAdmin
PHP extension not loading: Run php -m | grep memcach — if empty, the extension is not installed for the active PHP CLI version. Check /etc/php.d/ or /usr/local/lib/php.ini for the extension directive.
WordPress not using Memcached after plugin setup: Check that a object-cache.php drop-in file is NOT already in wp-content/ — a conflicting drop-in from another plugin overrides your setup.
Memcached evicting too aggressively: Increase CACHESIZE in the Memcached config. You can also reduce cache lifetime (TTL) values in W3 Total Cache to keep only fresh, frequently-used objects.
Port 11211 not responding: Confirm Memcached is bound to 127.0.0.1 and running: ss -tlnp | grep 11211
For expert performance tuning of DirectAdmin servers including Memcached, OPcache, PHP-FPM, and database optimization, CloudHouse Technologies provides professional server management with a focus on WordPress hosting performance.
