- বিজ্ঞাপন -

Install Redis Server on CentOS

linux
- বিজ্ঞাপন -

Assalamu Alaikum.
Welcome to Uddoyon, in this article we try to know How to Install Redis Server & Redis-PHP on CentOS System so keep reading…

Redis is an open-source, High-Performance, in-memory key-value store that is widely used for caching and data storage. In this guide, we will walk you through the process of installing Redis Server and the php-redis extension on an CentOS system. By the end of this tutorial, you’ll have a fully functional Redis Server and the ability to interact with it using PHP.

Prerequisites:
* A CentOS system (tested on CentOS 7,8).
* Access to a terminal with sudo privileges.
* Basic familiarity with the Linux command line.

    - বিজ্ঞাপন -

    Step 1: Update System Packages
    Start by updating the package list and upgrading existing packages to their latest versions:

    sudo yum update

    Step 2: Install Redis Server
    To install Redis on CentOS, use the following command:

    sudo yum install redis

    Step 3: Start and Enable Redis
    After installation, start the Redis service and enable it to start on system boot:

    sudo systemctl start redis
    sudo systemctl enable redis

    Step 4: Configure Redis (Optional)
    The default Redis configuration usually works well, but you can make adjustments as needed. The configuration file is located at “/etc/redis.conf”.

    Step 5: Install php-redis Extension
    To integrate Redis with PHP, you need to install the php-redis extension. You can do this using the following steps:

    sudo yum install php-redis

    Step 6: Restart Web Server
    After installing the php-redis extension, you need to restart your web server to ensure that the changes take effect. For Apache, use:

    sudo systemctl restart httpd

    For Nginx, use:

    sudo systemctl restart nginx

    Step 7: Verify Installation
    To ensure that Redis and the php-redis extension are installed correctly, you can create a simple PHP script that connects to Redis and performs basic operations. Create a file named ‘test-redis.php’ in your web server’s document root and add the following code:

    <?php
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);
    echo "Connection to Redis server successfully!";
    $redis->set('my_key', 'Hello, Redis!');
    echo "Stored value in Redis: " . $redis->get('my_key');
    ?>

    Access the script via a web browser (http://your_server_ip/test-redis.php) to see if Redis is working as expected.

    Congratulations! You have successfully installed Redis Server and the php-redis extension on your CentOS server. Redis can now be used as a powerful data store and caching mechanism for your PHP applications, enhancing their performance and scalability. Make sure to explore Redis documentation to fully leverage its capabilities in your projects.

    Thanks for Reading, stay with us to know more things as like this.

    - বিজ্ঞাপন -
    Exit mobile version