How to Install Redis and PHP Redis on a cPanel Server?

How to Install Redis and PHP Redis on a cPanel Server?

In the realm of web development, cPanel users operating Linux-based servers often find themselves in need of robust tools to enhance their project performance. One such indispensable tool is Redis, an open-source, in-memory data structure store. In this blog post, we will walk you through the process of installing and configuring Redis on your cPanel server.

Why Redis?

Before we delve into the installation process, let’s take a moment to understand why Redis is a popular choice for developers working with PHP. Redis acts not only as an efficient key-value store but also supports various data structures, including strings, hashes, lists, sets, and sorted sets. Its in-memory storage capability allows for seamless handling of large data amounts without compromising data transfer performance. Furthermore, Redis employs a passive data caching mechanism, ensuring optimal performance by removing outdated cache while incorporating new content.

Installation Steps

Let’s get started with the installation process. Follow these steps to install Redis on your cPanel server:

1. SSH into Your cPanel Server:

   Log in to your cPanel server using SSH.

2. Download RPM Files:

   Run the following commands to download the necessary RPM files for Redis:

   # wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

   # wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

3. Install Redis:

   Execute the following commands to install Redis:

   # rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

   # yum install –y redis

4. Enable Redis:

   Run the following command to enable Redis, ensuring it starts automatically upon server reboot:

 # chkconfig redis on

Configuration Steps

Now that Redis is installed, let’s configure it to suit your needs:

5.Edit Redis Configuration File:

   Open the `redis.conf` file using a text editor:

   vi /etc/redis.conf

6. Add Configuration Lines:

   Enter or copy the following lines at the end of the file to set basic Redis configurations:

   conf

   maxmemory 256mb

  maxmemory-policy allkeys-lru

These configurations ensure optimal performance and memory management for Redis on your server.

Installing PHP Redis Extension

With Redis set up, the final step is to install the PHP Redis extension to integrate Redis with PHP:

1.Install PHP Redis Extension:

   Run the following command to install the PHP Redis extension:

      # yum install –y php-pecl-redis

Congratulations! You’ve successfully installed and configured Redis on your cPanel server, enhancing the performance of your PHP projects. Redis, coupled with cPanel, provides a robust environment for developers to build and scale their applications effectively.

To install PHP Redis

1. Log in to WHM with root access:

   – Open your web browser and navigate to WHM (Web Host Manager) using your server’s URL.

   – Log in with the root credentials.

2. Select the Software option from the navigation menu:

   – Once logged in, navigate to the “Software” section in WHM.

3. Click on Module Installers:

   – Under the Software section, locate and click on “Module Installers.”

4. Click Manage for PHP Pecl:

   – Within Module Installers, find and click on “Manage” next to “PHP Pecl.”

   The PHP Pecl Installer section will open. 

   Ensure that you see the “Find a PHP PECL” section.

5. Type “redis” in the Search box and click Go:

   – In the “Find a PHP PECL” section, enter “redis” in the search box.

   – Click the “Go” button.

6. Click Install:

   – The search results will display the appropriate PHP Redis module. Click on the “Install” button next to the PHP Redis module.

   This will install the PHP extension that serves as an interface for Redis.

7. Run the following commands in SSH:

   – Open an SSH terminal to your server.

   # service httpd restart

   # service redis restart

   These commands will restart both Apache (httpd) and Redis to apply the changes.

   With these steps, the installation of Redis and PHP Redis on your cPanel server should be complete. Verify the installation by checking the PHP configuration or running test scripts to ensure that the Redis extension is functioning as expected.