When should services like memcache be used?

How to install Memcached on Ubuntu 18.04 LTS

Memcached is a free and open source memory object cache system that can be used to speed up your applications by temporarily storing information in memory. Memcached helps you speed up web applications like WordPress, Drupal, Joomla and other PHP based applications.

In this tutorial we are going to explain how to install Memcached on Ubuntu 18.04 server.


  • A server with Ubuntu 18.04.
  • A root password is configured on your server.

Update your system

First, update all packages to the latest version using the following command:

apt-get update -y apt-get upgrade -y

Once all the packages are updated, reboot your system for the configuration changes to take effect.

Installation and configuration of Memcached

By default, Memcached is available in the Ubuntu 18.04 standard repository. You can install it by simply running the following command:

apt-get install memcached libmemcached-tools -y

After installing Memcached, start the Memcached service and activate it after a system restart with the following command:

systemctl start memcached systemctl enable memcached

You can now check the status of the Memcached service with the following command:

systemctl status memcached

You should see the output similar to this:

? memcached.service - memcached daemon Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2019-07-13 06:13:59 UTC; 13s ago Docs: man: memcached (1) Main PID: 21776 (memcached) Tasks: 10 (limit: 1114) CGroup: /system.slice/memcached.service ?? 21776 / usr / bin / memcached -m 64 -p 11211 -u memcache -l -P /var/run/memcached/memcached.pid Jul 13 06:13:59 ubuntu1804 systemd [1]: Started memcached daemon.

You can also check that the Memcached service is running by typing:

ps aux | grep memcached

You should see the following output:

memcache 21776 0.3 0.2 424764 2880? Ssl 06:13 0:00 / usr / bin / memcached -m 64 -p 11211 -u memcache -l -P /var/run/memcached/memcached.pid root 22035 0.0 0.0 13136 1000 pts / 0 S + 06 : 14 0:00 grep --color = auto memcached

Next, you need to configure Memcached for advanced settings. To do this, open the /etc/memcached.conf file as shown below:

nano /etc/memcached.conf

Change the following lines according to your needs:

# Default connection port is 11211 -p 11211 # Specify which IP address to listen on. -l # Define the maximum number of memory can be used by Memcached deamon. -m 256

Save and close the file, and then restart the Memcached services for the changes to take effect.

systemctl restart memcached

Install Apache and PHP and configure PHP to use Memcached

Memcached is now installed and configured. Next, you need to install and configure Apache to use Memcached.

First, install Apache and PHP with other modules using the following command:

apt-get install apache2 php7.2 libapache2-mod-php7.2 php-memcached php7.2-cli -y

Next, create a sample phpinfo.php file in the Apache web root directory to test Memcached.

nano /var/www/html/phpinfo.php

Add the following code:

<?php phpinfo(); ?>

Save and close the file. Then open your web browser and enter the url http: //your-server-ip/phpinfo.php a. You should see all the PHP related modules and memcached information on the following page:

Congratulations! You have successfully installed Memcached on the Ubuntu 18.04 server. For more information, see the official documentation at Memcache Doc. Don't hesitate to ask me if you have any questions.