Mastering the installation of PHP via RPM packages on CentOS is an essential skill in enterprise and development environments. Using RPM simplifies the installation process and facilitates future software management and upgrades. This guide walks you through configuring necessary repositories, installing PHP and common extensions, and performing basic PHP-FPM setup to run PHP smoothly on CentOS.
Before starting, ensure you have administrative access to a CentOS system and basic command-line skills. Also, make sure the yum package manager is installed. Begin by updating the system and installing essential tools to prepare the environment.
Run system update:
sudo yum update
Install necessary tools like wget:
sudo yum install wget
To install the latest PHP versions, enable the EPEL and Remi repositories. EPEL provides additional open-source packages, while Remi offers multiple PHP version options.
Install the EPEL repository:
sudo yum install epel-release
Install the Remi repository:
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Enable the desired PHP version repository via yum-config-manager, for example, PHP 7.4:
sudo yum-config-manager --enable remi-php74
You may also enable other versions such as remi-php80 or remi-php81 according to your project needs.
Run the following command to install the PHP core and common extensions:
sudo yum install php php-cli php-fpm php-mysqlnd
After installation, check the PHP version to confirm success:
php -v
If the terminal displays PHP version info, the installation is successful.
Install more extensions as needed, such as for image processing and multibyte string support:
sudo yum install php-gd php-mbstring
If you use PHP-FPM, edit its configuration file to match your web server settings:
sudo vi /etc/php-fpm.d/www.conf
Adjust the user and group as necessary to align with your web server permissions.
This guide explained how to install and manage PHP on CentOS using RPM packages, including repository setup, installation, extension addition, and basic PHP-FPM configuration. RPM-based installation offers centralized package management and easy upgrades, ideal for building a stable, maintainable PHP environment suitable for web applications and API services.