How to install PHP Version 8.0 and 8.1 on CentOS 7

How to install PHP Version 8.0 and 8.1 on CentOS 7

PHP stands for Hypertext Preprocessor. PHP is a server-side scripting language that is widely used for development. It is used to create PHP bashed websites and applications. It is developed by Rasmus Lerdorf in 1994. Now PHP is maintained by the official PHP Development Team.

PHP supports almost every operating system such as Windows, Linux, and macOS.

Advantages of PHP

  • Simple – PHP is very simple to understand
  • Quick – PHP based applications and websites are very fast
  • Open Source – PHP is an open source. It means you can use and modify it as per your requirement.


  • CentOS 7 Operating System
  • Root user or another user with Sudo privileges

PHP Modules

PHP modules are used to make connect PHP with different types of applications. For example, the PHP module mysqli is used to connect PHP with MySQL. These are the list of mostly used PHP modules.


Update the server

Before starting the PHP installation, make sure that the server repositories are up-to-date. To update the server, run the following command.

yum update -y

Enable the REMI Repository

  • PHP packages are not available in the default repositories, so we need to install and enable the REMI repository. To enable the REMI repository, run the following command.
yum install -y

Install PHP 8.0

  • Run the following command to install PHP 8.0 with their modules.
yum install php80-php php80-php-opcache php80-php-xml php80-php-hash php80-php-mysqlnd php80-php-mbstring php80-php-ldap php80-php-curl php80-php-imap php80-php-zip php80-php-json php80-php-mysqli php80-php-intl php80-php-gd php80-php-fpm php80-php-cli php80-php-imagick php80-php-zlib -y

Install PHP 8.1

  • Run the following command to install PHP 8.1 with their modules.
yum install php81-php php81-php-opcache php81-php-xml php81-php-hash php81-php-mysqlnd php81-php-mbstring php81-php-ldap php81-php-curl php81-php-imap php81-php-zip php81-php-json php81-php-mysqli php81-php-intl php81-php-gd php81-php-fpm php81-php-cli php81-php-imagick php81-php-zlib -y
  • Now, to check the PHP version, run the following command.
php -v
  • If the above command shows an error that the command is not found, then you need to change the default PHP version to 8.0 or 8.1 for a session.

For PHP 8.0

scl enable php80 bash

For PHP 8.1

scl enable php81 bash
  • To check the PHP modules, run the following command.
php -m
  • To check the installed PHP version on the server.
yum list installed | grep php

Set the default PHP version

To change the default PHP version permanently, we need to create a symbolic link of the PHP binaries.

  • Change your current working directory to /bin/, and run the following command to change the directory.
cd /bin/
  • Filter the installed PHP version’s binaries with the help of the following command.
ls -l | grep php

You will get the output like this:-

Check PHP versions and binaries
  • Delete the existing default PHP symbolic link with the following command.
rm -rf /bin/php
  • Run the following command to create the symbolic link for PHP 8.0.
ln -s /opt/remi/php80/root/usr/bin/php php

Now check the PHP version with the following command.

php -v
Check the PHP versions

Note:- Path in the above may vary from system to system, but in most cases, it will be the same. If you want to create the symbolic link for PHP 8.1 then delete the default PHP symbolic line and create a new symbolic with PHP 8.1 as mentioned above.


In this tutorial, we learned about PHP and some of its features, we have also learned how we can install PHP 8.0 and 8.1 with their modules on CentOS 7. You can also learn how we can install PHP 7.0 to 7.4 on CentOS with our previous blog.

If you guys have any queries or issues, then let me know in the comments section.