Memcached is a highly popular caching service. It can be used as a backend for WordPress object cache or as a storage engine for Cachify static caching. After installing the Memcached service on your server, you also need to install the Memcached PHP extension so that PHP applications can connect to the Memcached service.
How to Install the Memcached Extension in cPanel
In cPanel, you can easily install the Memcached extension via the command line.
For CentOS-based Linux systems, use the following command to install it:
yum install ea-phpXX-php-memcached
For Debian-based systems, use the following command:
apt-get install ea-phpXX-php-memcached
Note: Replace XX with your specific PHP version (e.g., 81 for PHP 8.1).
After the installation is complete, you can restart php-fpm using the following command:
/scripts/restartsrv_apache_php_fpm --status
If you are using environments configured with LNMP or the Pagoda (BT) panel, they also provide convenient tools to help install PHP extensions. You can simply use their respective management tools to perform the installation.
Verify if the Memcached Extension is Working
After following the installation steps, you can write a simple PHP script to verify if the Memcached extension is successfully connected.
$memcache = new Memcached();
$memcache->addServer('localhost', 11211);
if ($memcache->set('test_key', 'Hello World')) {
echo "Connection successful, test data written successfully.";
echo "Data retrieved: " . $memcache->get('test_key');
} else {
echo "Connection failed";
}
Run the code above. If it displays “Connection successful…”, it means your PHP environment can now normally use the Memcached service. At this point, you can start using Memcached to optimize and speed up your WordPress site.
