Cloud Service >> Knowledgebase >> cPanel >> How to Install Redis and PHP Redis on a cPanel Server?
submit query

Cut Hosting Costs! Submit Query Today!

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

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

 

The installation process of Redis and PHP Redis on a cPanel server is quite simple. However, one has to pay close attention while doing it. The following procedures involve using WHM (Web Host Manager) to accomplish this.

Prerequisites

Before starting, ensure:

 

 

- You have root access to your cPanel server

- You are familiar with WHM.

- You'll also need a basic understanding of SSH.

Step 1: Log in to WHM

- Open your web browser.

- Navigate to your WHM login page (https://your-server-ip:2087)

- Sign in with your root username and password.

Step 2: Update Your Server

Update your server packages before installing new software.

Log in to your server via SSH as the root user and run:

yum update -y

It ensures all your existing packages are up-to-date.

Step 3: Install Redis

- Add the Remi Repository

Redis is unavailable in the default CentOS repository, so you must add the Remi repository. Execute the following commands in your SSH terminal:

yum install -y epel-release

yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm

- Enable the Remi Repository

Now, enable the Remi repository:

yum-config-manager --enable remi

- Install Redis

With the Remi repository enabled, you can now install Redis:

yum install -y redis

- Start and Enable Redis

Start the Redis service and ensure it starts automatically on boot:

systemctl start redis

systemctl enable redis

- Verify Redis Installation

Check if Redis is running

systemctl status redis

You should see a message indicating that Redis is active and running.

Step 4: Install PHP Redis Extension

You need to install the PHP Redis extension. It allows PHP to communicate with Redis. It can be done through PECL.

- Install Required Tools

First, ensure you have the necessary tools:

yum install -y php-pear php-devel

- Install PHP Redis Extension via PECL

Use PECL to install the Redis extension:

 

pecl install redis

- Enable the Redis Extension

After installation, you must enable the Redis extension in your PHP configuration.

 

Add extension=redis.so to your php.ini file.

 

The location of this file can vary, but common paths include

 

/etc/php.ini

or

/etc/php/7.x/php.ini.

 

echo "extension=redis.so" >> /etc/php.ini

- Restart Apache

To apply the changes, restart Apache:

systemctl restart httpd

Step 5: Verify PHP Redis Extension

Create a PHP info file to ensure the PHP Redis extension is installed and enabled correctly.

Create PHP Info File

Create a file named info.php in your web root directory (e.g., /var/www/html/):

phpinfo();

?>

- Access the PHP Info Page

Open your web browser and navigate to http://your-server-ip/info.php. Search for "Redis" on the page to confirm the extension is enabled.

 

Step 6: Configure Redis for cPanel

To integrate Redis with cPanel, you might need to adjust some configurations.

- Edit Redis Configuration

Open the Redis configuration file /etc/redis.conf and make necessary adjustments based on your requirements. For example, you might want to bind Redis to a specific IP or adjust the max memory usage.

nano /etc/redis.conf

After making changes, restart Redis:

systemctl restart redis

- Set Up Redis for PHP Sessions

If you plan to use Redis for PHP session handling, add the following lines to your php.ini file:

session.save_handler = redis

session.save_path = "tcp://127.0.0.1:6379

To Sum it Up!

Following the above steps, you have installed Redis and the PHP Redis extension in your cPanel server. This setup enables you to fully utilize Redis for caching and session handling in your web application, making it faster. Always ensure that Redis and PHP are tuned to perform optimally and securely for your needs.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!