October 15, 2026 · by Alex M.
The performance of a web application depends heavily on how quickly it can access frequently requested data. Every database query consumes resources and adds latency. Memcached solves exactly this problem: it temporarily stores query results in RAM, allowing subsequent requests to be served in microseconds rather than milliseconds.
In this guide, you'll learn how to install, configure, and optimize Memcached on a SSD VPS running Ubuntu 22.04, including integration with PHP and WordPress.
Memcached is an open-source, distributed in-memory caching system. It acts as an intermediate layer between your application and the database:
If you're running WordPress, WooCommerce, Drupal, or any high-traffic application on a NVMe VPS, Memcached can dramatically reduce server load.
Before you start, make sure you have:
sudo privilegesIf you don't have a server yet, you can quickly order a SSD VPS from CLIQHOST with Ubuntu pre-installed.
Before any installation, update system packages:
sudo apt update && sudo apt upgrade -y
Install Memcached and the development library needed for the PHP extension:
sudo apt install memcached libmemcached-tools -y
Check if the service started automatically:
sudo systemctl status memcached
You should see active (running). If not, start it manually:
sudo systemctl start memcached
sudo systemctl enable memcached
The main configuration file is located at /etc/memcached.conf. Open it with your preferred editor:
sudo nano /etc/memcached.conf
Here are the most important directives:
# Memory allocated (in MB)
-m 256
# Listening port (default 11211)
-p 11211
# User under which the process runs
-u memcache
# Listening address — IMPORTANT: localhost only for security
-l 127.0.0.1
# Maximum simultaneous connections
-c 1024
# Maximum size of a single cached object (in MB)
-I 5m
| VPS RAM | Memory for Memcached |
|---|---|
| 1 GB | 128–256 MB |
| 2 GB | 256–512 MB |
| 4 GB | 512 MB – 1 GB |
| 8 GB+ | 1–2 GB |
On a NVMe VPS with dedicated resources, you can allocate more memory without impacting other services.
After making changes, restart Memcached:
sudo systemctl restart memcached
Memcached has no native authentication in standard versions, so network-level security is essential.
Verify that the -l directive in /etc/memcached.conf is set to 127.0.0.1 (not 0.0.0.0).
sudo ufw deny 11211
sudo ufw allow OpenSSH
sudo ufw enable
sudo ss -tlnp | grep memcached
Correct output:
LISTEN 0 1024 127.0.0.1:11211 0.0.0.0:*
If Memcached's port is publicly exposed, your server can be exploited for UDP amplification DDoS attacks. CLIQHOST's server management service includes security audits for exactly these kinds of misconfigurations.
To connect PHP applications to Memcached, you need the php-memcached extension:
sudo apt install php-memcached -y
For a specific PHP version (e.g., 8.1):
sudo apt install php8.1-memcached -y
Restart your web server:
# For Nginx + PHP-FPM
sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx
# For Apache
sudo systemctl restart apache2
Verify the extension is active:
php -m | grep memcached
This should return: memcached
The memcstat tool from the libmemcached-tools package lets you check server status:
memcstat --servers=127.0.0.1:11211
Alternatively, use telnet for a quick test:
telnet 127.0.0.1 11211
In the telnet console, type:
set test_key 0 60 5
hello
get test_key
Expected response:
STORED
VALUE test_key 0 5
hello
END
Memcached is working correctly! Exit telnet with quit.
WordPress can use Memcached as an Object Cache backend, eliminating repeated queries to the MySQL/MariaDB database.
Option 1: Dedicated "Memcached Object Cache" Plugin
Download the object-cache.php file from WordPress.org and place it in /wp-content/object-cache.php:
cd /var/www/html/wp-content/
wget https://raw.githubusercontent.com/tollmanz/wordpress-memcached-backend/master/object-cache.php
Add to wp-config.php before /* That's all, stop editing! */:
$memcached_servers = array(
'default' => array(
'127.0.0.1:11211'
)
);
Option 2: W3 Total Cache
From the WordPress admin panel:
If you're running WordPress on optimized WordPress hosting or a VPS, this configuration significantly reduces TTFB (Time To First Byte).
Memcached exposes detailed statistics accessible in real time.
telnet 127.0.0.1 11211
stats
The most important metrics:
| Metric | Description |
|---|---|
curr_items |
Number of objects stored in cache |
get_hits |
Requests served from cache |
get_misses |
Requests not found in cache (accessed from DB) |
bytes |
Memory used (bytes) |
limit_maxbytes |
Configured maximum memory limit |
evictions |
Objects evicted from cache due to memory limits |
hit_rate = get_hits / (get_hits + get_misses) * 100
A hit rate above 90% indicates an effective configuration. If evictions keep rising, increase the -m value in your config.
You can install the phpMemcachedAdmin web interface for a graphical view:
cd /var/www/html
git clone https://github.com/elijaa/phpmemcachedadmin.git
Always configure restricted access (HTTP Basic Auth) before exposing it publicly.
The Memcached binary protocol is more efficient than ASCII. Enable it by adding to /etc/memcached.conf:
-B binary
⚠️ Make sure your PHP client (the
php-memcachedextension) supports binary protocol — thephp-memcacheextension (without "d") supports only ASCII.
On a VPS with multiple CPU cores, you can increase the number of worker threads:
-t 4
If you're storing large objects (complete HTML pages), adjust slab settings:
-f 1.25
-n 128
On a dedicated-resource VPS, these optimizations make a noticeable difference under heavy traffic scenarios.
A frequent question: when should you use Memcached vs. Redis?
| Criteria | Memcached | Redis |
|---|---|---|
| Data types | Strings only | String, list, hash, set, sorted set |
| Disk persistence | No | Yes (optional) |
| Native cluster | Yes (client-side) | Yes (Redis Cluster) |
| Memory footprint | Smaller | Slightly larger |
| Best for | Simple cache, sessions | Complex cache, pub/sub, queues |
For simple WordPress Object Cache, Memcached is sufficient and easier to configure. For more complex applications (message queues, pub/sub, persistent data), Redis is the better choice.
sudo journalctl -u memcached -n 50
Common cause: port 11211 already in use. Check:
sudo ss -tlnp | grep 11211
php --ini | grep memcached
Verify that the extension's .ini file exists in PHP's conf.d directory.
Memcached is a simple, robust, and highly effective solution for speeding up PHP-based web applications. Installation on a Linux VPS takes under 10 minutes, and the performance gain can be substantial — especially for high-traffic sites with large databases.
If you want a solid foundation for your projects, choose a SSD VPS or a NVMe VPS from CLIQHOST, with guaranteed resources, technical support, and the option of full server management. Need help with the setup? Contact the CLIQHOST team — we're ready to assist.
Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.
"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."
"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."
"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."