Home Linux CentOS How To Install and Setup PHP 7.4 on CentOS 7

How To Install and Setup PHP 7.4 on CentOS 7

857
0

The latest stable version of PHP 7.4.0 has been released to the public a few days ago and brings many improvements, as well as new features. It’s generally available for public since November 28 2019, so we can safely use PHP 7.4 on our server. PHP 7.4 is obviously much faster and better than previous PHP 7 versions, since it has brought many bug fixes. This release also marks the fourth feature update for the PHP 7 series.

Following are some of the improvements and new features brought by PHP 7.4.

  • Typed Properties
  • Arrow Functions
  • Limited Return Type Covariance and Argument Type Contravariance
  • Unpacking Inside Arrays
  • Numeric Literal Separator
  • Weak References
  • Allow Exceptions from __toString()
  • Opcache Preloading
  • Several Deprecations
  • Extensions Removed from the Core

Here we will not explain in more detail about the new features and improvements for PHP 7.4. So you can simply open the official PHP website to read more details about improvements, changes and new features brought by PHP 7.4.0.

This tutorial will guide you on how to install and setup the latest stable release of PHP 7.4 on CentOS 7 server. Well, to install PHP 7.4 on CentOS 7 is very easy. It’s exactly like we installed the other PHP 7 version on CentOS 7. Just follow the following guide to configure PHP 7.4 on your CentOS 7 server.

READ:  How To Fix Missing Kernel-Headers on CentOS 7

1.) Update System and Software Packages

$ yum update -y
$ yum install wget nano screen telnet zip unzip -y

2.) Install EPEL and REMI Repository

Just like installing PHP 7.3 / PHP 7.2 / PHP 7.1 / PHP 7.0, we still need the REMI and EPEL RPM’s Repositories in order to install PHP 7.4 on CentOS 7.

$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
$ yum --enablerepo=remi update remi-release

3.) Install and Configure PHP 7.4

After that, simply run the following command to install and configure PHP 7.4 along with its dependencies on your CentOS 7 server. As before, we still give you two choices here. You can easily configure PHP 7.4 for Apache, or PHP 7.4 with FastCGI Proccess Manager (PHP-FPM) for the Nginx web server.

* Setup PHP 7.4 with FastCGI Process Manager (PHP-FPM):

$ yum --enablerepo=remi-php74 install php74-php php74-php-pear php74-php-bcmath php74-php-pecl-jsond-devel php74-php-mysqlnd php74-php-gd php74-php-common php74-php-fpm php74-php-intl php74-php-cli php74-php php74-php-xml php74-php-opcache php74-php-pecl-apcu php74-php-pecl-jsond php74-php-pdo php74-php-gmp php74-php-process php74-php-pecl-imagick php74-php-devel php74-php-soap php74-php-mcrypt php-mcrypt php-soap php74-php-mbstring phpMyAdmin roundcubemail memcached php74-php-pecl-memcached php74-php-pecl-memcache php-redis redis php74-php-redis php74-php-zip php74-php-pspell php-brotli

* Setup PHP 7.4 with Apache HTTP Web Server

$ yum --enablerepo=remi-php74 install php74-php php74-php-pear php74-php-bcmath php74-php-pecl-jsond-devel php74-php-mysqlnd php74-php-gd php74-php-common php74-php-intl php74-php-cli php74-php php74-php-xml php74-php-opcache php74-php-pecl-apcu php74-php-pecl-jsond php74-php-pdo php74-php-gmp php74-php-process php74-php-pecl-imagick php74-php-devel php74-php-mbstring php74-php-soap php74-php-mcrypt php-mcrypt php-soap phpMyAdmin roundcubemail memcached php74-php-pecl-memcached php74-php-pecl-memcache php-opcache php-redis redis php74-php-redis php74-php-zip php74-php-pspell php-brotli

4.) Fix PHP Session Save Handler and Save Path

* For PHP-FPM:

$ nano /etc/php.ini
$ nano /etc/opt/remi/php74/php.ini
session.save_handler = files
session.save_path = /var/lib/php/session
soap.wsdl_cache_dir = /var/lib/php/wsdlcache

* For Apache/HTTPD:

$ nano /etc/php.ini
$ nano /etc/opt/remi/php74/php.ini
session.save_handler = files
session.save_path = /var/lib/php/session
soap.wsdl_cache_dir ="/tmp"

After that, we need to set correct permission for PHP session directory. Run the following command.

$ chmod 777 /var/lib/php/session/

5.) Check PHP Version

$ php -v
$ php74 -v
PHP 7.4.0 (cli) (built: Nov 26 2019 20:13:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

6.) Create Symbolic Link for PHP 7.4 with FastCGI Process Manager (PHP-FPM)

If you’ve configured PHP 7.4 with FastCGI Process Manager (PHP-FPM) on CentOS 7, you must run the following command to create a symbolic link for PHP 7.4.

$ rm -f /usr/bin/php
$ ln -s /usr/bin/php74 /usr/bin/php

7.) Remove OLD PHP-FPM Systemd Service File and Symlink to the New PHP74-PHP-FPM

$ rm -f /usr/lib/systemd/system/php-fpm.service
$ ln -s /usr/lib/systemd/system/php74-php-fpm.service /usr/lib/systemd/system/php-fpm.service

Reload Systemd Manager

$ systemctl daemon-reload

8.) Restart Apache / Nginx and PHP-FPM

Finally, we need to restart the following services to ensure your server runs properly, depending on the web server you are using.

READ:  How To Install and Configure PHP 7.3 on CentOS 7

* Restart PHP7.4-FPM

$ service php-fpm start "OR" service php74-php-fpm restart

* Restart Apache / HTTPD

$ service httpd restart

* Restart Nginx

$ service nginx restart

LEAVE A REPLY

Please enter your comment!
Please enter your name here