PHP is a popular server-side scripting language and widely used for creating interactive and dynamic web pages. PHP 7.3 is the latest stable version of PHP. We will use
Remi repository to install PHP 7 on CentOS 7 server.
Installing PHP 7 on CentOS 7
In this tutorial, we will show you how to install PHP 7.3, PHP 7.2 or PHP 7.1 on CentOS 7 system.
The user you are logged in as must have sudo privileges enabled to be able to install packages.
Configure Yum Repository
At first, you have to install and enable EPEL and Remi yum repository on your CentOS 7 server. Run the below commands to install and enable EPEL and Remi yum repository.
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Now we are going to install
yum-utils. It is a collection of useful programs for managing yum repositories and packages. It has tools that improve yum’s default features.
sudo yum install yum-utils
Next, we wil use
yum-config-manager program which is included in
yum-utils. We will use it to enable Remi repository as the default repository for installing different PHP versions.
Now you can install latest stable version of PHP on your server. Run the following commands to install PHP 7 on CentOS 7 server.
First choose specific php version of your choice and enable appropriate Remi repository for install PHP 7 as below:
For PHP 7.3
sudo yum-config-manager --enable remi-php73
For PHP 7.2
sudo yum-config-manager --enable remi-php72
For PHP 7.1
sudo yum-config-manager --enable remi-php71
After that, install PHP 7 with additional necessary modules which can extend the core functionality. Run below command:
sudo yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
Now, PHP is installed with specific version. Afterwards, you can check the installed PHP version.
Verify PHP Installation
You can check installed PHP version using command line by type:
sudo php -v
It will show you output as below:
PHP 7.3.1 (cli) (built: Jan 8 2019 13:55:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies
In order to test verify that your system is configured properly for PHP, create a very basic PHP script called info.php file.
So create this file at web root of server. In CentOS 7 directory is located at
/var/www/html/ so create file here by executing this command :
sudo nano /var/www/html/info.php
Add the following PHP code inside the file:
At last, Save and close file. Now visit this page in web browser using your server’s public IP address as following :
It should show as following screenshot:
You learned how to install specific version of PHP 7 on CentOS 7 Linux server. You can send us any questions or additional thoughts by leave a comment below.