How to install PHP 7.2 on CentOS 7
Install PHP 7.2 on CentOS 7
PHP is a server-side scripting language used for web development. PHP comes in different versions 5.6, 7.0, 7.1, 7.2, etc. Currently PHP 7.2 is the latest version of PHP. The CentOS 7 official repository supports PHP 5.4, but it does not receive any updates. You need to migrate to PHP 7.2 to get the latest security updates and features. In this tutorial you will learn how to install PHP 7.2 on CentOS.
Before you start installing PHP 7.2 on CentOS 7, you need a non-root user account with sudo privileges on the server.
1. Install PHP on CentOS
PHP 7.2 cannot be used with CentOS Global Repository. You must add it manually. To enable PHP 7.2 on the CentsOS repository, enter the following text in a terminal:
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
If not installed
yum-utils Enter the following command:
sudo yum install yum-utils
Enable the PHP 7.2 Remi repository by entering the following command:
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php72
Enter the following text to install PHP 7.2:
sudo yum install php72
Check the installation of PHP 7.2.
The output is as follows:
# php72 -v PHP 7.2.10 (cli) (built: Oct 22 2018 02:02: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
ln -s /usr/bin/php72 /usr/bin/php
Then type and confirm the version.
4. Install PHP extensions
To run frameworks such as WordPress, Ghost, etc. on your server, you need to install some basic PHP extensions. To install any of the PHP extensions on the server, use the following basic format
sudo yum install php72-php-[name_of_the_extension]
You can install the curl extension for PHP by running the following command:
sudo yum install php72-php-curl
Below are the basic PHP extensions that need to be installed on the server.
sudo 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
To install additional extensions, you can use the specified format.
5. PHP processing test
To test that PHP is properly configured on the server, you need to create a file test.php in the directory var / www / html / with the following code:
If you see the following output in https: //YOUR_DOMAIN_NAME/test.php or https: //IP_ADDRESS/test.php, you have successfully installed PHP.
I learned and tested how to install PHP 7.2 on CentOS 7 and some of its basic extensions. If you have any questions about this, don't forget to comment below.