Current Location: Home> Latest Articles> Complete Guide to Installing PHP and Redis on CentOS

Complete Guide to Installing PHP and Redis on CentOS

gitbox 2025-08-04

Comprehensive Guide to Installing PHP and Redis on CentOS

This article will walk you through the process of installing PHP and Redis on a CentOS system. Whether you're building dynamic websites or improving application performance, mastering the installation and configuration of these two components is essential. The following content will help you get started quickly and ensure a stable environment.

System Preparation

Before starting, make sure your CentOS system packages are up to date. Run the following command to update the system:

<span class="fun">sudo yum update -y</span>

PHP Installation Steps

The default CentOS repositories may not provide the latest PHP versions, so it's recommended to use the Remi third-party repository for installing and managing PHP versions. First, install the EPEL and Remi repositories:

sudo yum install epel-release -y
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y

Enable the Remi PHP Repository

Enable the desired PHP version repository, for example, PHP 7.4:

<span class="fun">sudo yum-config-manager --enable remi-php74</span>

Install PHP and Common Extensions

Install PHP along with common extensions required for most applications:

<span class="fun">sudo yum install php php-mysqlnd php-fpm php-curl -y</span>

Verify PHP Installation

After installation, verify the PHP version to confirm a successful installation:

<span class="fun">php -v</span>

Redis Installation Process

Install Redis quickly through the EPEL repository:

<span class="fun">sudo yum install redis -y</span>

Start and Enable Redis Service

After installation, start the Redis service and enable it to start on boot:

sudo systemctl start redis
sudo systemctl enable redis

Check Redis Service Status

Use the Redis CLI tool to check if the service is running properly:

<span class="fun">redis-cli ping</span>

If you get a PONG response, the Redis service is working correctly.

Conclusion

By following this guide, you can successfully install and configure PHP and Redis on your CentOS system. This sets a solid foundation for building high-performance web applications. From here, you can further configure PHP extensions and Redis caching strategies according to your project needs to improve overall application efficiency.

If you encounter any issues, it is recommended to consult official documentation or community resources for more detailed assistance.