How to Install PHP on CentOS 8

Published: September 15, 2020 (Updated: Sep 15, 2020)

Enjoying this content? Subscribe to the Channel!

Get Your Server Ready: The Quick and Easy Way to Install PHP on CentOS 8 (and RHEL)


Introduction

Welcome back to Darren’s Tech Tutorials! If you’re running a CentOS or Red Hat Enterprise Linux (RHEL) server and need to power a website, application, or CMS (like WordPress), you need PHP. PHP is the backbone of modern web development, and getting it installed on your Linux system is surprisingly simple.

Unlike complex installations that require juggling multiple repositories, CentOS makes this process straightforward. This guide translates our short video tutorial into clear, actionable steps, ensuring you have PHP up and running in minutes.

The best part? This exact installation method works perfectly not only for CentOS 8, but also for older versions like CentOS 7 and across most RHEL distributions!

Prerequisites

Before we start, make sure you have the following:

  1. Access to a CentOS (7 or 8) or RHEL server installation.
  2. An internet connection for downloading packages.
  3. Root or sudo privileges to execute administrative commands.

Step 1: Perform a System Update

It is always best practice to ensure your system’s package lists are current before installing new software. This helps prevent dependency conflicts and ensures you get the latest security patches for existing packages.

Open your terminal and run the following command:

sudo yum update

Allow the process to complete. If any major updates are applied, you may need to reboot, but typically you can proceed directly to the next step.

Step 2: Running the Core PHP Installation Command

The CentOS (and RHEL) repositories provide the necessary PHP package. Because the yum package manager is smart, it will automatically pull in all required dependencies needed for a functional PHP install.

This single, simple command is all you need:

sudo yum install php

What to expect after running this command:

  1. Dependency Check: Yum will list the main PHP package and all required supporting libraries (like php-common).
  2. Confirmation: You will be prompted to confirm the installation size. Type y and press Enter.
  3. Installation: Yum will download and install all necessary files.

Pro Tip: This command installs the default version of PHP available in the standard CentOS/RHEL base repositories. If you need a specific, newer version (like PHP 8.1 or 8.2), you might need to first enable an external repository like EPEL or Remi.

Step 3: Verifying Your PHP Installation

Once the command finishes, PHP is installed, but you must verify that the installation was successful and that the system recognizes the PHP command.

Run the version check command:

php -v

If successful, you will see output similar to this (the version number will depend on the release you are running):

PHP 7.2.24 (cli) (built: Oct 28 2019 14:38:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

This output confirms that the PHP Command Line Interface (CLI) is functional and ready to go!

Step 4: Integrating PHP with Your Web Server

If you are running a web server (like Apache HTTPD or Nginx), installing PHP alone isn’t enough; you need to make sure the web server can execute PHP files.

If you are using Apache HTTPD, you typically need to install the PHP module specific to Apache:

sudo yum install php-cli php-fpm

Then, you must restart your web server so it can load the newly installed PHP modules:

sudo systemctl restart httpd
# OR (if using Nginx and php-fpm)
sudo systemctl restart nginx
sudo systemctl restart php-fpm

Conclusion: Ready to Start Coding!

And there you have it! With one simple command, you’ve successfully installed the core PHP package onto your CentOS or RHEL server. You now have the necessary foundation to run powerful applications, develop custom websites, and manage popular content management systems.

Wasn’t that easy? Darren’s Tech Tutorials is dedicated to making complex server administration fast and stress-free.

If this quick guide helped you get your server running, please give the video a Like and Subscribe to Darren’s Tech Tutorials for more clear, accessible tech walkthroughs! Let us know in the comments what you’ll be building with your newly installed PHP environment!