Table of Contents
Install PHP 7.2 on CentOS 7
PHP is the server-side scripting language used for web development. PHP has different versions 5.6, 7.0, 7.1 and 7.2 etc. Currently, PHP 7.2 is the latest version of PHP. CentOS 7 official repository supports PHP 5.4 which will no longer receive any updates. To get the latest security updates and features you need to migrate to PHP 7.2. 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 must have the non-root user account on your server with sudo privileges.
1. Installing PHP on CentOS
As PHP 7.2 is not available in CentOS global repository. You will need to add it manually.
To Enable PHP 7.2 in CentsOS repository enter following text in terminal.
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
If you have not installed
yum-utils enter following command.
sudo yum install yum-utils
Now enable Remi Repositories for PHP 7.2 entering following command.
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php72
Install PHP 7.2 by typing the following text.
sudo yum install php72
Confirm installation of PHP 7.2.
Output should be:
# 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
Now check the version by typing.
4. Install PHP Extensions
You will need to install some basic PHP extensions to run WordPress, Ghost etc. frameworks on the server. To install any of the PHP extensions on the server following is the basic format
sudo yum install php72-php-[name_of_the_extension]
You can install curl extension for PHP by running following command.
sudo yum install php72-php-curl
Following are some basic PHP extensions needs to be installed on your 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 more extensions you can use the given format.
5. Testing PHP processing
To test PHP is configured on your server properly or not you should create a file test.php inside directory var/www/html/ with following code.
If you see the following output at https://YOUR_DOMAIN_NAME/test.php or https://IP_ADDRESS /test.php then you have installed PHP successfully.
You have successfully learned how to install PHP 7.2 on CentOS 7 with some of its basic extensions and tested. If you have any of the queries regarding this then don’t forget to comment below.