How To Install Memcached on Amazon Linux 2023

Memcached is a free to use and open source in-memory, high-performance and distributed key-value store for small chunks of arbitrary data (objects, strings) from results of database calls, API calls, or page rendering. Memcached is intended for use in speeding up dynamic web applications by alleviating database load. Memcached API is available for most popular programming languages.

In this short post we will be covering the installation of Memcached on Amazon Linux 2023 server. There is a Memcached package available in the default Amazon Linux 2023 repositories but the version is a bit old. In this guide we will download the latest release of Memcached source, extract and build the binary from it.

Install Memcached on Amazon Linux 2023

We will be doing the manual installation of Memcached on Amazon Linux 2023. We start by ensuring all dependencies are installed, then perform the actual building and installation of latest Memcached Server on Amazon Linux 2023.

Step 1: Install Build Dependencies

Install build dependencies using yum commands below.

sudo yum -y install '@Development Tools' openssl-devel libevent-devel

Step 2: Install Memcached on Amazon Linux 2023

Download the latest Memcached release source code.

wget https://memcached.org/latest -O memcached-latest.tar.gz

Once the file is downloaded extract it with tar command line tool.

tar xvf memcached-latest.tar.gz

Extract the downloaded archive file.

cd memcached-*/

Run configuration command:

./configure

Make and install.

make
sudo make install

Sample Output:

Step 3: Configure Systemd service file

Create Memcached systemd environment configuration file:

sudo tee /etc/sysconfig/memcached > /dev/null <<EOF
# These defaults will be used by every memcached instance, unless overridden
# by values in /etc/sysconfig/memcached.<port>
USER="nobody"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

# The PORT variable will only be used by memcached.service, not by
# memcached@xxxxx services, which will use the xxxxx
PORT="11211"
EOF

Create new Memcached Systemd unit file.

sudo vim /etc/systemd/system/memcached.service

And paste the following content:

[Unit]
Description=memcached daemon
After=network.target

[Service]
EnvironmentFile=/etc/sysconfig/memcached
ExecStart=/usr/local/bin/memcached -p ${PORT} -u ${USER} -m ${CACHESIZE} -c ${MAXCONN} $OPTIONS
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX

[Install]
WantedBy=multi-user.target

Reload Systemd.

sudo systemctl daemon-reload

Start Systemd service.

sudo systemctl enable --now memcached

Checking service status:

sudo systemctl status memcached -l

Step 4: PHP and Python usage

A Client specific to your programming language is required when connecting to Memcached server from your application.

For PHP

PHP Module installation:

sudo yum install php8.4 
sudo yum install php-pear php-devel

Download the latest php-memcache release from PECL repository.

pecl download memcache

Then extract and compile the memcache package using the commands below:

sudo tar -xzf memcache-8.2.tgz
cd memcache-8.2
sudo phpize
sudo ./configure
sudo make
sudo make install

Then edit php.ini and add extension=memcache.so

sudo vim /etc/php.ini

Confirm that the extension is loaded properly by running php --modules:

[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
memcache
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
random
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zlib

[Zend Modules]
Zend OPcache
For Python:
sudo yum -y install python3 python3-pip

Install Memcached Python module:

$ sudo pip3 install  python-memcached
Collecting python-memcached
  Downloading python_memcached-1.62-py2.py3-none-any.whl (15 kB)
Installing collected packages: python-memcached
Successfully installed python-memcached-1.62

More articles on Amazon Linux:

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

SQL stands for “structured query language” and it makes up the name MySQL, which is the combination of My and […]

PHP 8.4 is the latest major release of the PHP programming Language mostly used in the Development of Web Applications. It […]

Gitea is the fastest and most painless way of setting up a self-hosted Git service on premise, or in a […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.