How to Install PHP 7.4 on CentOS 8

By default PHP that is available on CentOS 8 is version 7.2, while Security Support from PHP 7.2 will soon end its support period on 30 November 2020. In some cases too, PHP applications that want to run on CentOS 8 require the latest version of PHP.

*0.Check the PHP Version*

Check the version of PHP that is read in the repository cache.

[INPUT]

1 2 3 4 5 6 7 8 9 10 dnf info php   Available Packages Name         : php Version      : 7.2.24 Release      : 1.module_el8.2.0+313+b04d0a66 Architecture : x86_64 Size         : 1.5 M Source       : php-7.2.24-1.module_el8.2.0+313+b04d0a66.src.rpm Repository   : AppStream

*1.Install EPEL and REMI Repository*

Install EPEL and REMI repository first.

[INPUT]

1 2 dnf install epel-release -y dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Check the PHP available in the module.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 dnf module list php   CentOS-8 – AppStream Name           Stream             Profiles                             Summary                         php            7.2 [d]            common [d], devel, minimal           PHP scripting language           php            7.3                common [d], devel, minimal           PHP scripting language             Remi’s Modular repository for Enterprise Linux 8 – x86_64 Name           Stream             Profiles                             Summary                         php            remi-7.2           common [d], devel, minimal           PHP scripting language           php            remi-7.3           common [d], devel, minimal           PHP scripting language           php            remi-7.4           common [d], devel, minimal           PHP scripting language             Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

*2.Enable PHP 7.4 Module Stream*

Enable *php:remi-7.4* module stream.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 dnf module enable php:remi-7.4   Dependencies resolved. ======================================================================================================= Package                 Architecture           Version                  Repository               Size ======================================================================================================= Enabling module streams: php                                            remi-7.4                                                 Transaction Summary =======================================================================================================   Is this ok [y/N]: y

*3.Install PHP 7.4*

Install PHP 7.4.

[INPUT]

1 dnf install php php-cli php-common

Test the results of the installation by checking the PHP version.

[INPUT]

1 2 3 4 5 6 php -v   PHP 7.4.7 (cli) (built: Jun  9 2020 10:57:17) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies     with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies

*4.PHP with Apache*

When installing PHP earlier also installed the Apache web server (HTTPD).

Enable and start the Apache service.

[INPUT]

1 2 3 systemctl enable httpd systemctl start httpd systemctl status httpd

Also check the php-fpm service status, because CentOS 8 no longer uses the Apache module. Install PHP had also already installed PHP-FPM.

[INPUT]

1 2 systemctl enable php-fpm systemctl status php-fpm

Create info.php file to test Apache whether it can run PHP scripts.

[INPUT]

1 2 cd /var/www/html echo “” > info.php

Browse http://SERVER-IP/info.php.

PHP Information

Good luck 🙂

Leave a Reply

Your email address will not be published.