Memcached is a widely-used open-source, in-memory caching system that speeds up web applications by reducing the amount of data that must be retrieved from a database. Installing Memcached on Amazon Linux 2023 is a straightforward process.
Table of Contents
Update the package repository:
Run the following command to update the package repository and ensure that you have the latest available packages installed:
sudo dnf update -y
Install Memcached:
Once the package repository has been updated, you can install memcached using the following command:
sudo dnf install memcached -y
Start Memcached:
Once memcached is installed, you can start the service with the following command:
sudo systemctl start memcached
Verify Memcached is running:
To verify that Memcached is running, use the following command:
systemctl status memcached
Configure Memcached:
By default, memcached listens on the loopback interface on port 11211 and has a maximum memory allocation of 64 MB. To configure these settings, you can edit the Memcached configuration file, “/etc/sysconfig/memcached”
Enable Memcached on startup:
To ensure that Memcached starts automatically when your Amazon Linux 2 instance starts, use the following command:
sudo systemctl enable memcached
After you have installed and configured Memcached on Amazon Linux 2, you can test the installation by inserting some data into the cache. You can do this by using a client library that is compatible with the memcached protocol, such as libmemcached.
Here’s how you can test memcached by inserting data using the command-line interface:
Connect and Insert Data
The Memcached command-line tool is not installed by default when you install the Memcached package. To install the tool, run the following command:
sudo dnf install telnet -y
Once you have installed the Telnet, you can insert data into the cache by using the following command:
set mykey 0 0 11
hello world
set mykey
: The key for your data.
0
: Flags (usually 0).
0
: Expiration time in seconds (0 means never expires).
11
: Number of bytes in the data.
hello world
: The actual data.
Retrieve data from the cache:
You can retrieve data from the cache by using the following command:
get mykey
This command retrieves the value of the key from the cache. If the key exists and has not expired, the value of the key will be returned.
Delete data from the cache:
To delete data from the cache, use the following command:
delete mykey
This command deletes the key and its associated value from the cache.
By testing the insertion, retrieval, and deletion of data, you can confirm that Memcached is working properly on your Amazon Linux 2023 instance.
Conclusion
That’s it! You have successfully installed and configured Memcached on Amazon Linux 2023. You can now use Memcached to cache data from your web applications and improve their performance.
Hi Atiqur,
I am unable to get memcached run on php cli but not php web server , memcached is not working in php ZTS (thread safe) for web