Memcached is a key-value store to cache the dynamic database calls and stores them in memory. This reduces the database load helps in speeding up the dynamic database driven websites.
In this guide you are going to learn how to install and configure Memcached in your server alongside with Apache and PHP on Ubuntu 20.04.
Update your server packages to the latest.
sudo apt update sudo apt upgrade -y
Make sure you have followed the prerequisites guides to install Apache and PHP 8.
Memcached is available by default in the Ubuntu 20.04 repository.
sudo apt install memcached libmemcached-tools -y
Once the installation is complete you can check the status.
sudo service memcached status
● memcached.service - memcached daemon Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-07-20 02:23:14 UTC; 39s ago Docs: man:memcached(1) Main PID: 9944 (memcached) Tasks: 10 (limit: 682) Memory: 1.6M CGroup: /system.slice/memcached.service └─9944 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid Jul 20 02:23:14 memcached systemd: Started memcached daemon.
Now you have Memcached up and running.
Configure Memcached for Apache and PHP
Install PHP memcached module using the following command.
sudo apt install php-memcached
Restart Apache for the changes to take effect.
sudo service apache2 restart
Verify Memcache Installation
Create a file inside the webroot directory with
You will see the output similar to the one below.
Now you have enabled Memcached support on your server.
Now you have learned how to install and configure Memcached with Apache and PHP on Ubuntu 20.04.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.