How to Update PHP 7.x to 7.4 on CentOS

Kevin Amayi Mar 04, 2025 PHP PHP CentOS
  1. Prerequisites Before Updating PHP
  2. Method 1: Using the Remi Repository
  3. Method 2: Using Software Collections (SCL)
  4. Method 3: Compiling PHP from Source
  5. Conclusion
  6. FAQ
How to Update PHP 7.x to 7.4 on CentOS

Updating PHP from version 7.x to 7.4 on CentOS is a crucial task for developers and system administrators who want to take advantage of the latest features and security improvements. PHP 7.4 introduces several enhancements, including improved performance, type declarations, and better error handling.

In this article, we’ll walk you through the step-by-step process of upgrading your PHP version on a CentOS system. Whether you’re managing a web server or developing applications, keeping your PHP version up to date is essential for optimal performance and security. Let’s dive into the methods to achieve this upgrade seamlessly.

Prerequisites Before Updating PHP

Before you begin the upgrade process, ensure that you have the following prerequisites in place:

  • A CentOS system with PHP installed (version 7.x).
  • Root or sudo access to your server.
  • A backup of your current PHP configuration and files, just in case something goes wrong during the upgrade.

Having these in place will help you avoid any potential issues during the update process.

Method 1: Using the Remi Repository

One of the most reliable ways to update PHP on CentOS is by using the Remi repository. This repository provides the latest versions of PHP and is widely used in the community. Here’s how you can do it:

First, you need to install the EPEL (Extra Packages for Enterprise Linux) repository, which is a prerequisite for the Remi repository.

sudo yum install epel-release

Next, install the Remi repository:

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

Now, enable the Remi repository for PHP 7.4:

sudo yum-config-manager --enable remi-php74

After enabling the repository, update PHP:

sudo yum update php

Finally, check the installed PHP version to confirm the upgrade:

php -v

Output:

PHP 7.4.x (cli) (built: ...)

By following these steps, you will have successfully upgraded your PHP version to 7.4. The Remi repository is a trusted source that ensures you receive the latest updates and security patches.

Method 2: Using Software Collections (SCL)

Another method to install PHP 7.4 on CentOS is by using Software Collections (SCL). This method allows you to install multiple versions of software on your system, including PHP. Here’s how to do it:

First, install the SCL repository:

sudo yum install centos-release-scl

Next, you can install PHP 7.4 along with common extensions:

sudo yum install rh-php74 rh-php74-php rh-php74-php-cli rh-php74-php-fpm

After the installation is complete, you need to enable the PHP 7.4 environment:

scl enable rh-php74 bash

To make sure PHP is running correctly, check the version:

php -v

Output:

PHP 7.4.x (cli) (built: ...)

Using Software Collections is beneficial as it allows you to run multiple PHP versions side by side. This is particularly useful for testing applications across different PHP versions without affecting your production environment.

Method 3: Compiling PHP from Source

If you want to have more control over your PHP installation, you can compile it from the source. This method is more complex but gives you the flexibility to customize your PHP installation. Here’s how to do it:

First, ensure you have the necessary development tools and libraries:

sudo yum groupinstall "Development Tools"
sudo yum install libxml2-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel

Next, download the PHP 7.4 source code:

wget https://www.php.net/distributions/php-7.4.x.tar.gz

Extract the downloaded file:

tar -xzf php-7.4.x.tar.gz

Change into the extracted directory:

cd php-7.4.x

Now, configure the build options:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --with-curl --with-openssl --enable-soap --with-mysqli

Compile and install PHP:

make
sudo make install

Finally, check the PHP version:

/usr/local/php/bin/php -v

Output:

PHP 7.4.x (cli) (built: ...)

Compiling PHP from source allows you to tailor your installation to meet specific application requirements. However, this method does require a good understanding of the build process and may take longer than using package managers.

Conclusion

Upgrading PHP from version 7.x to 7.4 on CentOS is a straightforward process, whether you choose to use the Remi repository, Software Collections, or compile from source. Each method has its own advantages, so you can choose the one that best fits your needs. Keeping your PHP version up to date is essential for maintaining security and performance in your applications. By following the steps outlined in this article, you can ensure a smooth upgrade process and enjoy the benefits of PHP 7.4.

FAQ

  1. How can I check my current PHP version?
    You can check your current PHP version by running the command php -v in your terminal.

  2. Is it safe to upgrade PHP on a production server?
    Yes, but it’s advisable to take backups and test the upgrade on a staging environment before applying it to production.

  3. What are the benefits of upgrading to PHP 7.4?
    PHP 7.4 offers improved performance, new features, and better error handling, which can enhance your application’s efficiency.

  1. Can I run multiple PHP versions on CentOS?
    Yes, you can run multiple PHP versions using Software Collections or by compiling from source.

  2. What should I do if my application is not compatible with PHP 7.4?
    If your application is not compatible, you may need to modify the code or continue using an older PHP version until it is updated.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe