Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Caching Server»How to Install Redis Cache Server on CentOS 7/6

    How to Install Redis Cache Server on CentOS 7/6

    By RahulMarch 4, 20203 Mins Read

    Redis is an in-memory data structure store, used as a database server, cache, and message broker. It also provides a PHP module for communication between PHP script with the Redis server. Redis is written in C programming language.

    Advertisement

    This tutorial will help you with the installation of the Redis server along with PHP Redis PHP extensions on a CentOS 7/6 server.

    Step 1 – Prerequisites

    First of all, log in to your server using shell access with the root account.

    ssh [email protected]
    

    Redis packages are not available under default yum repositories. You need to enable EPEL yum repository on your server first. Execute below command to enable:

    ### CentOS/RHEL 7 
    yum install epel-release
    
    ### CentOS/RHEL 6 
    rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    

    Step 2 – Install Redis Server

    Now, You can use the yum package manager to install the Redis server on a VPS. Execute command to install Redis on your systems:

    yum install redis
    

    After successfully installation start Redis service and enable auto-start on system reboot.

    ### CentOS/RHEL 7 
    systemctl enable redis
    systemctl start redis
    
    ### CentOS/RHEL 6 
    chkconfig redis on
    service redis restart
    

    Redis server is up and running on your system.

    Step 3 – Install Redis PHP extension

    We assume you already have PHP installed on your system. You must have PHP pear package installed on your system.

    yum install php-pear php-devel
    

    Now, execute commands to enable Redis PHP extension on your CentOS server.

    pecl install igbinary igbinary-devel redis
    

    After that execute a command to verify Redis PHP extension is enabled:

    php -m | grep redis
    

    Redis server has been installed on your system along with the PHP extension.

    Step 4 – Configure Redis as a Cache Server

    Redis can be started without a configuration file using a built-in default configuration. But to make any extra parameter changes you can use its configuration file that is: /etc/redis/redis.conf. Edit the Redis configuration file in a text editor to make changes

    vim /etc/redis/redis.conf
    

    Update the following values in the Redis configuration file according to your requirement. You can increase the max memory limit as per available on your server.

    maxmemory 256mb
    maxmemory-policy allkeys-lru
    

    The above configuration tells Redis to remove any key using the LRU algorithm when the max memory of 256mb is reached. Save the configuration file and restart the Redis service:

    Step 5 – Test Connection to Redis Server

    Use redis-cli tool to verify the connection between the Redis server and redis-cli.

    redis-cli
    
    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379>
    

    centos PHP redis
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    How to Change Redis Max Memory

    View 2 Comments

    2 Comments

    1. Recep Baltaş on March 3, 2020 10:29 am

      pecl command not found. Your article is incomplete.

      Reply
    2. Oliver Russell on June 25, 2018 8:26 am

      In case where users don’t have access root access, I don’t think they can use Redis extension there. In such a case, I would recommend to use Predis for configuring redis cache with a PHP based website. Installing and configuring predis is easy. You can install it on your server using following command:

      git clone git://github.com/nrk/predis.git

      and check whether it has been implemented correctly using following command:

      redis-cli monitor

      Source: https://www.cloudways.com/blog/redis-cache-with-custom-php/

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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