How to Install PHP 7.3 on CentOS 7

In this tutorial, we will guide you through the steps of installing the latest PHP version 7.3 on a CentOS 7 VPS.

PHP is a server-side scripting language, commonly used for Web development, but it is also used as a general-purpose programming language. It is the most popular server-side (back-end) programming language and it powers some of the most popular products on the market, such as WordPress, the most widely used content management system, as well as e-commerce platforms such as Magento and PrestaShop. PHP also powers customer relationship management software, enterprise resource planning software, and lots more. The process of installing PHP 7.3 on CentOS 7 is a pretty easy and straightforward task, and it can be done in less than 10 minutes.

PHP 7 offers much better performances and security improvements than its predecessors. Listed below are some of the new features and changes in PHP 7.3:

  • Flexible Heredoc And Nowdoc Syntaxes
  • Allow a Trailing Comma in Function Calls
  • JSON_THROW_ON_ERROR
  • Same Site Cookie
  • Deprecate and Remove Case-Insensitive Constants
  • list() Reference Assignment
  • is_countable Function
  • array_key_first(), array_key_last()
  • Argon2 Password Hash Enhancements

Prerequisites

  • CentOS 7 VPS
  • User with root privileges – All of our VPS hosting plans come with full root access. You can also use a user account with sudo privileges.

Step 1: Log in and Update the Server

Login to your CentOS 7 VPS via SSH as the root user:

ssh root@IP_Address -p Port_number

Replace ‘IP_Address‘ and ‘Port_number‘ with your actual IP address and SSH port number.

Step 2: Install PHP 7.3

CentOS 7 by default is shipped with PHP 5.4 at the time of writing this article, which is a very old and outdated version and it has reached its end of life in September 2015. This also adds security vulnerabilities onto your server if you use PHP in a web setting. Luckily, some trusted and well-maintained repositories offer newer versions of PHP. In this case we will install and use PHP 7.3 from the Remi repository.

First of all, check if PHP is already installed on your server. If it is installed, check what version your server is running. You can do it with the following command:

# php -v

Output:

PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

According to the output, PHP 5.4 is installed on our CentOS VPS, which we mentioned that it is the latest available version in the CentOS 7 repositories. In order to install PHP 7.3, we have to remove this version:

yum remove php*

Removing:
 php       
 php-cli   
 php-common
 php-mysql 
 php-pdo

This command will remove PHP and all installed PHP extensions.

Run the following commands to add the Remi and Epel repositories to your server, and install yum-utils, which is a collection of tools for managing yum repositories:

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils epel-release

Disable the PHP 5.4 repository, which is enabled by default:

yum-config-manager --disable remi-php54

and enable the PHP 7.3 repository:

yum-config-manager --enable remi-php73

After the Remi repository for PHP 7.3 is enabled, we can easily install it with the yum package manager.

yum -y install php

Installing:
 php                         
Installing for dependencies:
 libargon2                   
 php-cli                     
 php-common                  
 php-json

It will install PHP 7.3 and some of its dependencies, as shown in the output above.

Once the installation is completed, you can check the installed PHP version:

php -v

Output:
PHP 7.3.0RC5 (cli) (built: Nov  6 2018 10:22:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies

You can easily install all necessary PHP extensions using the same way, as long as they are available in the repository. For example, if you need the MySQL, Multibyte String (mbstring), Mcrypt and the SimpleXML Parser PHP extensoins, you can install them with the following command:

yum -y install php-mysqlnd php-mbstring php-pecl-mcrypt php-xml

You can test if the extensions is properly installed using the following command:

php -m |grep extension_name

For example, to test if the Multibyte String (mbstring) extension is installed, you can use the following:

php -m |grep mbstring

output:

mbstring

Step 3: Create a phpinfo Page

In order to check a detailed information about the installed PHP version, extension, settings, and much more, you can create a phpinfo page. It displays a big amount of useful information about PHP. Including information about the PHP version, PHP compilation options and extensions, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.

To do this, go to the web server’s document root directory

cd /var/www/html

and create a phpinfo.php file with the following content

vi phpinfo.php

<?php
phpinfo();
?>

Save the file and access http://YourIPaddress/phpinfo.php with your favorite web browser. You should get the following page

For more information about PHP, its configuration and features you can check their official documentation.


Of course, you don’t have to install PHP 7.3 on CentOS 7 if you use one of our PHP 7 VPS Hosting services, in which case you can simply ask our expert Linux admins to install the latest version of PHP on CentOS 7 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install PHP 7.3 on CentOS 7, please share it with your friends on the social networks using the sharing buttons, or simply leave a reply below. Thanks.

Leave a Comment