How to Install PHP 7.x on CentOS 7

Post Date: October 22, 2018
Last Updated: September 29, 2026

Introduction

This guide explains how to install PHP on CentOS 7 using a third-party YUM repository, since CentOS 7’s default repos only ship an older PHP version.

Two important updates from the original version of this guide: the Webtatic repository has been discontinued and its packages are no longer maintained or reliably available, so this guide now uses the Remi repository instead, which remains actively maintained. It’s also worth knowing that CentOS 7 itself reached end-of-life in June 2024 — if you’re setting up a new server today, consider AlmaLinux, Rocky Linux, or CentOS Stream instead, all of which continue to receive updates.

Prerequisites

  • CentOS 7 (or a compatible EL7-based distribution)
  • Root or sudo access
  • Apache installed (if you plan to serve PHP through it)

Architecture

  • CentOS 7’s default repos only include an older PHP version
  • A third-party repo (Remi) provides precompiled, newer PHP packages for CentOS/RHEL
  • Once enabled, yum treats the new PHP version like any other package — installable, updatable, and removable through the normal package manager

Steps

1. Set Up the EPEL and Remi Repositories

sudo yum install -y epel-release
sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Note: The original guide used the Webtatic repository, which has since been discontinued and is no longer a reliable source for PHP packages on CentOS 7. Remi’s repository remains actively maintained and is the current standard choice for this purpose.

2. Install yum-utils and Enable Your PHP Version

sudo yum install -y yum-utils
sudo yum-config-manager --enable remi-php<VERSION>

Replace <VERSION> with your target PHP version’s Remi stream name (for example, remi-php81 for PHP 8.1) — check Remi’s repository page for currently available versions, since older PHP branches eventually stop receiving new releases even within Remi’s repo.

3. Install PHP and Common Extensions

sudo yum install -y php php-cli php-common php-gd php-mbstring php-mysqlnd php-xml

Note: The original package list included php71w-mcrypt. The mcrypt extension is deprecated and was removed from PHP core years ago — skip it, and use PHP’s built-in OpenSSL functions for encryption instead if your application needs them.

4. Configure PHP

sudo cp /etc/php.ini /etc/php.ini.bak
sudo vi /etc/php.ini

Always back up the original file before editing, as shown above, so you have something to roll back to if a change causes issues.

5. Restart Your Web Server

sudo systemctl restart httpd.service

6. Verify

php -v

Confirm the version shown matches what you installed.

Conclusion

Installing PHP on CentOS 7 today means going through the Remi repository rather than Webtatic, which is no longer maintained. The process itself is the same shape as before — enable the repo, install the packages, configure php.ini, restart your web server — just with a currently supported source and PHP version.

Frequently Asked Questions

Why did the original Webtatic instructions stop working? The Webtatic repository was discontinued, so its packages are no longer being updated or reliably served, which is why this guide now uses Remi instead.

Should I still be using CentOS 7? CentOS 7 reached end-of-life in June 2024 and no longer receives security updates. For a new deployment, AlmaLinux or Rocky Linux (both CentOS-compatible) are the more durable choice.

Can I install multiple PHP versions side by side with Remi? To some extent — Remi provides separate streams for different PHP versions, but running multiple versions simultaneously typically requires using software collections (SCL) packages rather than the standard php package name used in this guide.

Using PHP and Cron to Automate Kannel Status Monitoring

Managing Multiple PHP Versions on Ubuntu Using APT

Talk to Our Technology Experts

Setting up or migrating a CentOS-based server? Our team can help with server configuration, PHP environment setup, and OS migration planning.

Connect with our technology experts.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top