How To Install PHP 8 on CentOS 7

Install PHP 8 on CentOS 7

In this tutorial, we will show you how to install PHP 8 on CentOS 7. For those of you who didn’t know, PHP is the most used scripting language for web development, both websites and web applications such as blogs, forums, e-commerce, etc. It was originally created by Rasmus Lerdorf in 1994.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step by step install of PHP 8 on CentOS 7.

Install PHP 8 on CentOS 7

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo clean all
sudo yum update
sudo yum install yum-utils

Step 2. Installing PHP 8 on CentOS 7.

Now we add EPEL and REMI repository to install PHP 8 on CentOS 7 Linux system:

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

After that, enable the module stream for PHP 8:

sudo yum-config-manager --disable 'remi-php*'
sudo yum-config-manager --enable remi-php80
sudo yum update

Finally, run the following command to install PHP 8:

sudo yum install php

Once successfully installed, you can ensure that the latest stable release of PHP 8 is installed on your system by using the command:

$ php -v
PHP 8.0.0 (cli) (built: Dec 07 2020 16:36:46) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

Step 3. Installing PHP 8 Extensions.

Install PHP extensions are simple with the following syntax:

sudo yum install php-(extension_name)

For example, install some commonly used php-extensions with the following command:

sudo yum install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

Step 4. Test PHP.

To test PHP, create a text file named info.php with the content below:

nano /var/www/html/info.php

Paste the following code:

<?php
phpinfo();

Save the file and you can now view this page in your web browser by visiting your server’s domain name or public IP address followed by /info.php: http://your_domain_or_IP-address/info.php

Congratulations! You have successfully installed PHP. Thanks for using this tutorial for installing PHP 8.0 on your CentOS 7 system. For additional help or useful information, we recommend you to check the official PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!