Memcached works to enhance performance by keeping a copy of commonly used script elements within the server’s memory in a form that is more easily read by the server thus reducing time. A bonus feature of this object cache is its ability to decrease the number of connections to your database. In this tutorial, we instruct how to install Memcached, but it’s important to note that when using Memcache in an application, the application must be specially coded or configured to store and retrieve data this cached data.
- We are logged in as root on an Ubuntu 16.04 VPS powered by Liquid Web!
- Installed and running Apache and PHP 7.
Installation of Memcached
Following best practices, we will do a quick package update by using the following command:
Install the Memcached daemon using
apt-get install memcached -y
Install the Memcache module for PHP functionality:
apt-get install php-memcached -y
Verify installation of Memcached
Use the php -m flag to show compiled modules while sorting through specifically looking for memcached.
php -m | grep memcached
At some point, you may find that you need to change the default settings of Memcached. These include adjusting the port number, memory for your cache, and the listening IP address.
Adjust these configurations by keeping the same flags (-m, -p, -u, -l), adjusting the letter or number after the flag and save the file by typing :wq.
# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# Default connection port is 11211
# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the few security measures that memcached has, so make sure
# it’s listening on a firewalled interface.
Restart your Memcached service to recognize the changes to this file:
systemctl restart memcached
Give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions or Experienced Hosting advisors to learn more about our VPS servers and how you can take advantage of these deals today!