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.
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>
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 desired PHP version repository, for example, PHP 7.4:
<span class="fun">sudo yum-config-manager --enable remi-php74</span>
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>
After installation, verify the PHP version to confirm a successful installation:
<span class="fun">php -v</span>
Install Redis quickly through the EPEL repository:
<span class="fun">sudo yum install redis -y</span>
After installation, start the Redis service and enable it to start on boot:
sudo systemctl start redis
sudo systemctl enable redis
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.
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.