How to Install PHP 8 on CentOS 8

Install PHP 8 on CentOS 8

In this tutorial, we will show you how to install PHP 8 on CentOS 8. For those of you who didn’t know, PHP (PHP: Hypertext Preprocessor) is a server-side scripting language designed for web development but also used as a general-purpose programming language. PHP code is interpreted by a web server with a PHP processor module, which generates the resulting web page: PHP commands can be embedded directly into an HTML source document rather than calling an external file to process data.

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 8.

Install PHP 8 on CentOS 8

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

sudo clean all
sudo dnf update
sudo dnf install dnf-utils

Step 2. Installing PHP 8 on CentOS 8.

PHP 8.0 is not available in the default repositories you need to install the Remi repository:

sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

After that, now you can reset the module and enable PHP 8.0:

sudo dnf module reset php
sudo dnf module install php:remi-8.0

Finally, run the following command to install PHP 8:

sudo dnf 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: Nov 26 2020 13: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 dnf install php-(extension_name)

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

sudo dnf install php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,fpm,mbstring,opcache,zip}

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 on your CentOS 8 system. For additional help or useful information, we recommend you 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!