Memcached is a high-performance, distributed memory caching system designed to speed up dynamic web applications by alleviating database load. This guide will walk you through the steps to install and configure Memcached on an Ubuntu server, ensuring even beginners can follow along.
What You’ll Need
- A server running Ubuntu
- Command line/SSH access to the server
- Basic understanding of Linux commands
Installing Memcached on Ubuntu
Step 1: Update Your Ubuntu Server
Always start by updating your system’s package list to ensure you get the latest versions of the software.
sudo apt update && sudo apt upgrade -y
Step 2: Install Memcached
With your system updated, install Memcached and its PHP extension with the following command:
sudo apt install memcached libmemcached-tools php-memcached -y
Step 3: Verify the Installation
Ensure Memcached is installed correctly by checking its status.
sudo systemctl status memcached
Configuring Memcached on Your Ubuntu Server
Adjusting Memory Usage
One of the key configurations for Memcached is limiting its memory usage, crucial for optimizing server performance.
Step 1: Edit the Memcached Configuration File
Open the configuration file in your preferred text editor.
sudo nano /etc/memcached.conf
Step 2: Limit the Memory Usage
Find the line -m 512
. This line specifies Memcached is allocated 512MB of memory. Adjust this value based on your server’s available memory and needs.
Step 3: Restart Memcached
For the changes to take effect, restart Memcached.
sudo systemctl restart memcached
Enabling and Starting Memcached Service
Step 1: Enable Memcached to Start at Boot
sudo systemctl enable memcached
Step 2: Start the Memcached Service
sudo systemctl start memcached
Verifying Memcached Operation
Checking Memcached Stats
You can check Memcached’s operation and performance using memcached-tool
.
memcached-tool 127.0.0.1:11211 stats
Conclusion
This guide has walked you through the simple steps of installing and configuring Memcached on an Ubuntu server. By following these steps, you can improve the performance of your web applications significantly.