How To Install and Configure PHP 7.3 on CentOS 7

DigitalOcean Referral Badge
Start your VPS now with FREE $100 credit.

PHP 7.1 will reach its end-of-life (EOL) in the next 11 days. The official PHP site says that they only provide security support for PHP 7.1 until December 1, 2019.

So, the latest stable PHP version currently is PHP 7.2 and PHP 7.3.

According to the official PHP site, PHP 7.2 will get active support until November 30, 2020 or in other word PHP 7.2 will only get bug fixes and security maintenance for the next 1 year.

Since PHP 7.2 will only get active support for the next 10 days (30 Nov 2019)

Of course, we strongly recommend you to using the latest stable version of PHP 7.3, instead of PHP 7.2.

Considering that PHP 7.3 brings many significant performance improvements and bug fixes compared to the previous versions.

In addition, PHP 7.3 will get active support until December 6, 2020 (1 year) and security support for the next 2 years (until December 6, 2021).

So, with long-term active support and security, using PHP 7.3 will be more guaranteed on your server.

However, it doesn’t matter if you want to use PHP 7.2 on your server, for example due to software compatibility reasons.

If you want to install and setup the latest stable version of PHP 7.3, simply follow the following tutorial.

We will guide you step by step on how to configure PHP 7.3 on fresh CentOS 7 server.

1. Update System and Software Packages

First of all, don’t forget to update your CentOS 7 system and its software packages, as well as install the necessary tools.

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

2. Install EPEL and REMI RPM’s Repository for CentOS 7

Before we can install and setup PHP 7.3 on CentOS 7, we must first add REMI and EPEL Release 7 repository to your system. Simply run the following command to add these repos.

$ 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. Let’s Install and Setup PHP 7.3

Here’s command to install and setup PHP 7.3, both for Apache (HTTPD) or Nginx web server with PHP-FPM (PHP FastCGI Proccess Manager).

READ:  How To Reinstall Linux Kernel on CentOS 7 (Solving Kernel Panic Error)

Please note that you must always use PHP-FPM if you want to run a Nginx web server on your CentOS 7 system.

* Install and Configure PHP 7.3 with Apache (HTTPD)

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

The PHP 7.3 installation command above includes the Apache 2.4 (HTTPD) web server, so you don’t need to run another command to install HTTPD on CentOS 7.

You can check your Apache (HTTPD) version by running the following command.

[root@dev /]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Aug 8 2019 11:41:18

* Install and Configure PHP 7.3 with FastCGI Process Manager (FPM):

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

If you’ve installed PHP73-PHP-FPM on CentOS 7, don’t forget to also install the Nginx web server. Simply run the following command to install Nginx.

$ yum install nginx -y

Check Nginx Version:

[root@dev /]# nginx -v
nginx version: nginx/1.16.1

4. Edit php.ini Files

Afte we have successfully install PHP 7.3, we need to fix some values on php.ini file, including uncomment for session.save_handler and session.save_path.

The rules are different for Apache and PHP-FPM with Nginx, depending on the web server you are using.

READ:  Installing VMware Tools in CentOS 7, The Complete Guide

* For PHP-FPM:

$ nano /etc/php.ini
$ nano /etc/opt/remi/php73/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/php73/php.ini
$ session.save_handler = files
$ session.save_path = /var/lib/php/session
$ soap.wsdl_cache_dir ="/tmp"

* Set correct folder permission for PHP session directory

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

5. Check PHP Version

Let’s check the PHP version via the shell command or you can upload the phpinfo.php file to your server’s public folder (document root).

[root@dev ~]# php -v
PHP 7.3.12 (cli) (built: Nov 19 2019 10:24:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.12, Copyright (c) 1999-2018, by Zend Technologies

To create phpinfo.php file, simply paste this code into phpinfo.php

<?php
phpinfo(); 
?>

6. PHP 7.3 with FastCGI Process Manager (FPM)

If you’ve installed and configured PHP 7.3 with FastCGI Process Manager (PHP-FPM), you need to create symbolic link (symlink) for PHP 7.3.

After that, remove old PHP-FPM systemd service file and link to new one. This step must be done to make PHP73-PHP-FPM work well on your CentOS 7 server.

Create Symbolic Link for PHP 7.3

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

Remove Old PHP-FPM Systemd Service File and Link to New One

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

Reload Systemd Manager Configuration

$ systemctl daemon-reload

7. Restart Apache / Nginx and PHP-FPM

Ok all done, now let’s restart some service like Apache, Nginx and PHP-FPM.

$ service httpd restart
$ service nginx restart
$ service php-fpm start

Leave a Comment