PHP is a widely used server-side scripting language in modern web development, and PHP-FPM (FastCGI Process Manager) significantly enhances PHP performance. This tutorial walks you through the correct steps to install and configure PHP-FPM on CentOS 7.
Start by making sure your system packages are up to date. Run the following command in your terminal:
sudo yum update -y
PHP-FPM isn't included in the default CentOS repositories. Install EPEL and Remi repositories first:
sudo yum install epel-release -y
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
After installing the repositories, enable the PHP 7.4 Remi repo (or another version if needed):
sudo yum-config-manager --enable remi-php74
You can also enable other versions like remi-php80 or remi-php81 depending on your project requirements.
Once the repo is enabled, install PHP and the PHP-FPM package using:
sudo yum install php php-fpm -y
After installation, you need to configure PHP-FPM. Edit its main configuration file:
sudo vi /etc/php-fpm.d/www.conf
Locate the following lines and change the values to match your web server user (e.g., nginx):
user = nginx
group = nginx
Now start the PHP-FPM service and enable it to launch on boot:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
Verify that PHP-FPM is running correctly with the following command:
sudo systemctl status php-fpm
If the status shows active (running), the service has started successfully.
With this guide, you've successfully installed and configured PHP-FPM on CentOS 7. PHP-FPM provides efficient process management and can significantly improve the performance of PHP applications. It's an essential component for building fast and reliable production environments.