Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Distributions»CentOS»How To Install Memcached on CentOS/RHEL 8

    How To Install Memcached on CentOS/RHEL 8

    RahulBy RahulAugust 8, 20201 Min ReadUpdated:August 8, 2020

    Memcached is a distributed memory object caching system which stored data in memory on key-value basis. It is very useful for optimizing dynamic websites and enabled speed by caching objects in memory. Read more about Memcache.

    This article will help you to install Memcached and PHP Memcache extension on CentOS 8 and RHEL 8 Linux systems.

    Prerequisites

    You must have a running CentOS 8 or RHEL 8 Linux system with sudo privileged account access.

    Step 1 – Install Memcached Server

    The Memcached rpm packages are available under the default packages repository on CentOS/RHEL 8 systems.

    First, update the DNF cache on your system. After that install Memcached using the following commands. This will also install required libraries on your system.

    sudo dnf update -y
    sudo dnf install memcached libmemcached -y
    

    Above commands will install Step 2 – Memcached Configuration

    You have successfully installed Memcached server. Now configure your Memcache server for various options.

    Memcached service configuration file is /etc/sysconfig/memcached, Edit the configuration file in your favorite text editor:

    sudo  vi /etc/sysconfig/memcached
    

    Now update the following values as per your requirements.

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

    Here the options are:

    • PORT – Define the port number to Memcahe service listen on. The default Memcached port is 11211.
    • USER – Set the username under which the Memcached service run
    • MAXCONN – Set the maximum connection to accept at any time
    • CACHESIZE – Set the cache limit
    • OPTIONS – You an pass additional options to service. The -l option is used to define ip address to which application listen for. You can change this value to LAN/WAN IP to allow Memcache to listen for remote addresses.

    Save your file and close it.

    Step 3 – Manage Memcached Service

    Now start Memcached service by running the following command.

    sudo systemctl start memcached
    

    You also need to enable Memcached service to start on system boot. Run below command to do this:

    sudo systemctl enable memcached
    

    The Memcached service is up and running now. To view the stats of the Memcached service, execute following command from terminal. This will provide all details about the Memcached service.

    echo "stats settings" | nc localhost 11211 
    

    Output:

    STAT maxbytes 67108864
    STAT maxconns 1024
    STAT tcpport 11211
    STAT udpport 0
    STAT inter 127.0.0.1,::1
    STAT verbosity 0
    STAT oldest 0
    STAT evictions on
    STAT domain_socket NULL
    STAT umask 700
    STAT growth_factor 1.25
    STAT chunk_size 48
    STAT num_threads 4
    STAT num_threads_per_udp 1
    STAT stat_key_prefix :
    ...
    ...
    END
    

    Step 4 – Adjust Firewall Rules

    Additionally, we need to allow traffic to the Memcached server by opening the default port ( port 11211) on the firewall.

    Therefore, run the commands below:

    sudo firewall-cmd --zone=public --permanent --add-port=11211/tcp
    sudo firewall-cmd --reload
    

    Step 5 – Install PHP Memcached Extension

    To connect Memcache service from a PHP based applications, you need to install Memcache PHP extension. This extension must be installed on the same server where PHP application is running on. If your PHP application also running with CentOS/RHEL 8 system, follow below instructions to enable Memcached extension.

    There are two type of extensions available for PHP. First is Memcache is used by earlier version of PHP applications. The latest PHP Application’s uses “Memcached” extension. The below commands will install both (Memcache and Memcached) extension on your CentOS 8 and RHEL 8 system.

    sudo dnf install epel-release -y
    sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
    sudo dnf module reset php
    sudo dnf module enable php:remi-7.4 -y
    sudo dnf install php-pecl-memcached php-pecl-memcache -y
    

    Restart Apache service to enable extension

    sudo systemctl restart httpd.service
    

    Now check if memcache PHP extension is enabled and working properly. Create a phpinfo.php file using following code

    sudo vi /var/www/html/phpinfo.php
    

    PHP
    1
    2
    3
    <?php
      phpinfo();
    ?>

    Now access phpinfo.php on web interface and search for Memcache or Memcached, You will get result like below.

    http://server-ip-addr/phpinfo.php
    

    Installing Memcached CentOS 8

    Conclusion

    In this tutorial you have learned to install Memcached caching server on CentOS/RHEL 8 system. Also installed PHP Memcached extension.

    CentOS 8 memcache memcached
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous Article10 Amazing Tips & Tricks to Work with Linux
    Next Article How to Install Django Framework in Ubuntu 20.04

    Related Posts

    How To Install Security Updates on CentOS 8 (Manual + Automatic)

    4 Mins Read

    How to Install PHP 8 on CentOS/RHEL 8

    3 Mins Read

    How to Install Python 3.9 on CentOS/RHEL 8

    Updated:July 17, 20213 Mins Read

    How to Install Let’s Encrypt (Certbot) on CentOS 8

    Updated:September 11, 20203 Mins Read

    How To Install Memcached on Ubuntu 20.04

    3 Mins Read

    How To Install Apache Solr 8.9 on CentOS/RHEL 8

    Updated:June 28, 20213 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.