AWS Google Cloud Linux

How to Install and Configure Memcached with Apache and PHP

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

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

Install Memcached

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 -P /var/run/memcached/
Jul 20 02:23:14 memcached systemd[1]: 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 phpinfo() function.

You will see the output similar to the one below.

Memcache Installation with PHP

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.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.