Atlantic.Net Blog

How to Install and Configure Memcached on CentOS 8

Hitesh Jethva
by Atlantic.Net (76posts) under VPS Hosting
0 Comments

Memcached is an open-source and high-performance in-memory caching system. Generally, it is used to speed up web applications by caching session data, user authentication tokens, and API calls. Its aim is to accelerate dynamic web applications by alleviating database load.  Memcached reduces application load by storing data objects in dynamic memory.

In this tutorial, we will explain how to install Memcached on CentOS 8.

Prerequisites

  • A fresh CentOS 8 VPS on the Atlantic.net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing CentOS 8 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your CentOS 8 server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Install Memcached

By default, Memcached is available in the CentOS 8 default repository. You can install it by just running the following command:

dnf install memcached libmemcached -y

After installing Memcached, start the Memcached service and enable it to start at boot with the following command:

systemctl start memcached
systemctl enable memcached

You can also verify the status of the Memcached service with the following command:

systemctl status memcached

You should see the following output:

memcached.service - memcached daemon
   Loaded: loaded (/usr/lib/systemd/system/memcached.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-08-07 06:30:57 EDT; 10s ago
 Main PID: 9933 (Memcached)
    Tasks: 10 (limit: 12537)
   Memory: 3.6M
   CGroup: /system.slice/memcached.service
           └─9933 /usr/bin/memcached -p 11211 -u memcached -m 64 -c 1024 -l 127.0.0.1,::1

Aug 07 06:30:57 centos8 systemd[1]: Started memcached daemon.

Step 3 – Configure Memcached

Memcached default configuration file is located at /etc/sysconfig/memcached. By default, Memcached is configured to listen on the localhost. If your application is hosted on the same server, then you don’t need to configure Memcached. If your application is hosted on the remote server, then you will need to configure Memcached to listen on that IP address and allow access to the Memcached port 11211 only from the client IP address.

To see the Memcached default configuration, run the following command:

cat -n /etc/sysconfig/memcached

You should see the following output:

     1     PORT="11211"
     2     USER="memcached"
     3     MAXCONN="1024"
     4     CACHESIZE="64"
     5     OPTIONS="-l 127.0.0.1,::1"

If you want to configure Memcached for a remote application, you need to replace the 127.0.0.1 with the IP address of the remote system.

Step 4 – Integrate Memcached with PHP

If you want to use Memcached as a caching database for your PHP application, then you will need to install the Memcached extension for PHP.

First, you will need to install the EPEL and Remi repository in your system. You can install them by running the following command:

dnf install epel-release -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Next, enable the PHP Remi repository with the following command:

dnf module enable php:remi-7.4 -y

Next, install the PHP Memcached extension with the following command:

dnf install php-pecl-memcache php-pecl-memcached -y

Once you are finished, you can proceed to the next step.

Step 5 – Verify Memcached

Next, install the Nginx web server and create a sample PHP page to test whether Memcached is enabled for PHP or not.

First, install Nginx with PHP by running the following command:

dnf install nginx php php-cli -y

Once installed, create a sample info.php page:

nano /var/www/html/info.php

Add the following lines:

<?php
phpinfo();
?>

Save and close the file, then create a symbolic link of info.php file to the Nginx default web root directory:

ln -s /var/www/html/info.php /usr/share/nginx/html/

Next, start the Nginx server and enable it to start at boot with the following command:

systemctl start nginx
systemctl enable nginx

Now, open your web browser and type the URL http://your-server-ip/info.php. You should see the Memcached section in the following screen:

Conclusion

Congratulations! You have successfully installed and configured Memcached on CentOS 8. You can now integrate your web application with Memcached and use its features to speed up your website on VPS hosting from Atlantic.Net. For more information, visit the Memcached documentation.

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources