Installation via Yum
Yum automates the instalation process by resolving and installing all required software dependencies. In CentOS 7, system services are managed with systemctl. A yum installation automatically registers the service, allowing you to start it with commands like systemctl start php74-php-fpm.service. The primary disadvantage is the lack of control over installation paths and version selection; packages are distributed across standard system directories. For instance, the default CentOS 7 repositories provide PHP 5.4. To install newer versions, you must add third-party repositories.
This guide uses the Remi repository. First, add the necessary repositories:
sudo yum install -y epel-release
sudo rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
Proceed to install the core PHP 7.4 package:
sudo yum install -y --enablerepo=remi-php74 php
Install additional PHP extensions as needed. The naming convention for extensions in this repository is php-<extension_name>.
sudo yum install -y --enablerepo=remi-php74 php-gd php-xml php-sockets php-session php-snmp php-mysqlnd
Verification, Management, and Path Setup
Check the enstalled PHP version:
php -v
Manage the PHP-FPM service:
# Restart the service
sudo systemctl restart php-fpm
# Enable automatic startup on boot
sudo systemctl enable php-fpm
Find the PHP binary location and create a symbolic link if necessary:
# Locate the PHP installation
whereis php
# Example: Create a link (adjust path if different)
sudo ln -sf /usr/bin/php /usr/local/bin/php
Configuration File Locations
Primary configuration files are located in /etc/php.ini and the PHP-FPM pool directory. To adjust settings like memory limit:
sudo vi /etc/php.ini
# Find and modify the line:
# memory_limit = 128M
# Change to:
memory_limit = 512M
If using Nginx with PHP-FPM, configure the apppropriate user and group in the pool configuration:
sudo vi /etc/php-fpm.d/www.conf
# Locate and change these lines:
# user = apache
# group = apache
# To:
user = nginx
group = nginx
After modifying these files, restart the PHP-FPM service for changes to take effect.
Removing PHP 7.4
To completely remove PHP 7.4 and its associated packages:
sudo yum remove -y 'php*'