Install PHP 7.4 on CentOS 7

This article will show you how to install PHP 7.4 on CentOS 7. PHP is a popular general-purpose scripting language that is especially suited to web development. It was one of the first server-side languages to be integrated in HTML, making it easy to add functionality to web pages without having to access data from separate files. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.

How to Install PHP 7.4 on CentOS 7

  • Install the EPEL yum repository on your system with yum-utils using the following command.
sudo yum install epel-release yum-utils -y
  • Using the yum command, download and install remirepo.
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Sample Output

Loaded plugins: fastestmirror, langpacks
remi-release-7.rpm                                                       |  23 kB  00:00:00     
Examining /var/tmp/yum-root-CosmjH/remi-release-7.rpm: remi-release-7.9-3.el7.remi.noarch
Marking /var/tmp/yum-root-CosmjH/remi-release-7.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package remi-release.noarch 0:7.9-3.el7.remi will be installed
--> Processing Dependency: epel-release = 7 for package: remi-release-7.9-3.el7.remi.noarch
Loading mirror speeds from cached hostfile
 * base: centos.mirror.liquidtelecom.com
 * extras: centosn8.centos.org
 * updates: centose9.centos.org
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================
 Package               Arch            Version                   Repository                Size
================================================================================================
Installing:
 remi-release          noarch          7.9-3.el7.remi            /remi-release-7           35 k
Installing for dependencies:
 epel-release          noarch          7-11                      extras                    15 k

Transaction Summary
================================================================================================
Install  1 Package (+1 Dependent package)

Total size: 50 k
Total download size: 15 k
Installed size: 59 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm                                             |  15 kB  00:00:01     
Running transaction check
  • Next configure PHP 7.4 repository
sudo yum-config-manager --enable remi-php74

Sample output

Loaded plugins: fastestmirror, langpacks
============================================================ repo: remi-php74 ============================================================
async = True bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7 baseurl = cache = 0 cachedir = /var/cache/yum/x86_64/7/remi-php74 check_config_file_age = True compare_providers_priority = 80 cost = 1000 deltarpm_metadata_percentage = 100 deltarpm_percentage = enabled = 1 enablegroups = True exclude = failovermethod = priority ftp_disable_epsv = False gpgcadir = /var/lib/yum/repos/x86_64/7/remi-php74/gpgcadir gpgcakey = gpgcheck = True gpgdir = /var/lib/yum/repos/x86_64/7/remi-php74/gpgdir gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi hdrdir = /var/cache/yum/x86_64/7/remi-php74/headers http_caching = all includepkgs = ip_resolve = keepalive = True keepcache = False mddownloadpolicy = sqlite mdpolicy = group:small mediaid = metadata_expire = 21600 metadata_expire_filter = read-only:present metalink = minrate = 0 mirrorlist = http://cdn.remirepo.net/enterprise/7/php74/mirror mirrorlist_expire = 86400 name = Remi's PHP 7.4 RPM repository for Enterprise Linux 7 - x86_64 old_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/remi-php74 pkgdir = /var/cache/yum/x86_64/7/remi-php74/packages proxy = False proxy_dict = proxy_password = proxy_username = repo_gpgcheck = False retries = 10 skip_if_unavailable = False ssl_check_cert_permissions = True sslcacert = sslclientcert = sslclientkey = sslverify = True throttle = 0 timeout = 30.0 ui_id = remi-php74 ui_repoid_vars = releasever, basearch username =
  • Then run the following command to install latest version of PHP 7.4
sudo yum install php php-cli
  • Alternatively you can run the command below to install PHP7.4 along with its modules.
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

Sample output

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                       |  24 kB  00:00:00     
 * base: centos.mirror.liquidtelecom.com
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: centos.mirror.liquidtelecom.com
 * remi-php74: mirrors.ptisp.pt
 * remi-safe: mirrors.ptisp.pt
 * updates: centos.mirror.liquidtelecom.com
epel                                                                                                       | 4.7 kB  00:00:00     
remi-php74                                                                                                 | 3.0 kB  00:00:00     
remi-safe                                                                                                  | 3.0 kB  00:00:00     
(1/5): epel/x86_64/group_gz                                                                                |  96 kB  00:00:01     
(2/5): remi-php74/primary_db                                                                               | 254 kB  00:00:04     
(3/5): epel/x86_64/updateinfo                                                                              | 1.0 MB  00:00:21     
(4/5): remi-safe/primary_db                                                                                | 2.1 MB  00:00:23     
(5/5): epel/x86_64/primary_db                                                                              | 7.0 MB  00:01:01     
Package php-mcrypt is obsoleted by php-pecl-mcrypt, trying to install php-pecl-mcrypt-1.0.4-1.el7.remi.7.4.x86_64 instead
Package php-mysql is obsoleted by php-mysqlnd, trying to install php-mysqlnd-7.4.28-1.el7.remi.x86_64 instead
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:7.4.28-1.el7.remi will be installed
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-7.4.28-1.el7.remi.x86_64
--> Processing Dependency: php-sodium(x86-64) = 7.4.28-1.el7.remi for package: php-7.4.28-1.el7.remi.x86_64
--> Processing Dependency: httpd for package: php-7.4.28-1.el7.remi.x86_64
---> Package php-cli.x86_64 0:7.4.28-1.el7.remi will be installed
---> Package php-common.x86_64 0:7.4.28-1.el7.remi will be installed
--> Processing Dependency: php-json(x86-64) = 7.4.28-1.el7.remi for package: php-common-7.4.28-1.el7.remi.x86_64
---> Package php-gd.x86_64 0:7.4.28-1.el7.remi will be installed
--> Processing Dependency: libgd.so.103()(64bit) for package: php-gd-7.4.28-1.el7.remi.x86_64
---> Package php-mysqlnd.x86_64 0:7.4.28-1.el7.remi will be installed
--> Processing Dependency: php-pdo(x86-64) = 7.4.28-1.el7.remi for package: php-mysqlnd-7.4.28-1.el7.remi.x86_64
---> Package php-opcache.x86_64 0:7.4.28-1.el7.remi will be installed
---> Package php-pecl-mcrypt.x86_64 0:1.0.4-1.el7.remi.7.4 will be installed
--> Processing Dependency: libmcrypt.so.4()(64bit) for package: php-pecl-mcrypt-1.0.4-1.el7.remi.7.4.x86_64
--> Running transaction check
  • You are done installing PHP 7.4 on your Cent OS 7 system.
  • Use the command below to find all PHP modules.
sudo yum search php | more
  • Check which version of PHP is installed using the command below.
php -v

Sample output

PHP 7.4.28 (cli) (built: Feb 15 2022 13:23:10) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
  • Congratulations you have reached the end of the article. You have learned how to Install PHP 7.4 on CentOS 7.

Other Tutorials

Encrypt data using EncFS on Ubuntu 22.04

Install Guacamole remote desktop tool on Ubuntu 22.04

Install and Configure VNC server on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment