How to Install PHP 7.2 on CentOS 7

how to install php 7.2 on CentOS 7

installing php 7.2 on CentOS 7We will show you how to install PHP 7.2 on CentOS 7 as an operating system. PHP is a server-side scripting language commonly used for Web development, but it is also used as a general-purpose programming language. PHP powers WordPress, the most popular content management system used for blogging and building websites as well as may other e-commerce websites, customer relationship management software, enterprise resource planning software and much more. Installing PHP 7.2 on CentOS 7 is a pretty easy task and it should be completed in less than 10 minutes.

PHP 7 offers much better performances than PHP 5.6 and older PHP versions. Compared with PHP 5.6, PHP 7.2 could execute as much as three times more requests. If you have installed WordPress on your Linux VPS, this means much lower server load, thus you should expect your website to run faster with PHP 7.2.

In addition, PHP 7.2 offers some security improvements. There are some deprecations though that you may want to check before you consider upgrading to PHP 7.2.

1. Prerequisites

install php 7.2 on CentOS 7Before you install PHP 7.2 on your CentOS VPS, let’s make sure it is fully up to date. To update all your system software to the latest version you need to have root access to the server or at least you have sudo privileges with your system user. Connect to your Linux VPS via SSH and run the following command:

yum update

The software update will take few seconds or minutes depending on what packages need to be updated. Once it is completed you can proceed with enabling the required repositories. PHP 7.2 is not provided in the default CentOS 7 repositories, so you need to enable the following:

Enable EPEL:

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install yum-utils if it is not already installed.

yum install yum-utils

Enable the Remo repository for PHP 7.2:

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php72

Once you are done with these steps, you can go ahead and install PHP 7.2

2. Install PHP 7.2 on CentOS 7

To install PHP 7.2 on your CentOS 7 VPS, run the following command:

yum install php72 php72-php-fpm php72-php-mysqlnd php72-php-opcache php72-php-xml php72-php-xmlrpc php72-php-gd php72-php-mbstring php72-php-json

This will install PHP 7.2 as well as other commonly used PHP extensions. To verify PHP 7.2 is successfully installed, run the following command:

php72 -v

The output should be similar to the one below:

# php72 -v
PHP 7.2.10 (cli) (built: Sep 11 2018 10:09:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10, Copyright (c) 1999-2018, by Zend Technologies

Create a symbolic link to /usr/bin/php

ln -s /usr/bin/php72 /usr/bin/php

Verify again

php -v

The output should be similar to this:

# php -v
PHP 7.2.10 (cli) (built: Sep 11 2018 10:09:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10, Copyright (c) 1999-2018, by Zend Technologies

Once you have PHP 7.2 installed on your CentOS 7 VPS you may want to customize some of the settings. Follow the steps below to do so.

3. Customize the PHP 7.2 settings on CentOS 7

You can customize PHP 7.2 by editing the php.ini file. To find the path to this file, you can use the command below:

php --ini | grep "Loaded Configuration File"

The command will return the path to the php.ini file which is currently used.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
# php --ini | grep "Loaded Configuration File"
Loaded Configuration File: /etc/opt/remi/php72/php.ini

You can use any editor of your choice to edit the file. We will use nano in our example.

nano /etc/opt/remi/php72/php.ini

4. Verify if the PHP files are being executed on the serve

Once you change the settings you want to change, save and close the php.ini file. If you are using Apache as a web server, you need to restart the Apache service for the new configuration to be loaded and for the changes to take effect. If you are using Nginx and PHP-FPM instead of Apache, you should restart the PHP-FPM service.

To check if the PHP files are being executed on the server you can create a sample info.php file and access it via web browser.

nano /var/www/html/info.php

Paste the following content:

<?php phpinfo(); ?>

Save and close the file, then open your favorite web browser and access the file by using your server IP address in the URL followed by the name of the file.

http://IP-ADDRESS/info.php

install php 7.2 centos 7Of course, you don’t have to install PHP 7.2 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 PHP 7.2 on CentOS 7 for you. They are available 24×7 and will take care of your request immediately. You may also want to refer to this guide on how to install PHP 7.3 on CentOS 7 for updates.

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

3 thoughts on “How to Install PHP 7.2 on CentOS 7”

Leave a Comment