Understanding php.ini and PHP-FPM with Best Practices on Rocky Linux 8
Introduction
When running PHP applications (like WordPress, Joomla, or custom PHP apps) on Rocky Linux 8,
the performance depends a lot on how PHP is configured.
Two very important components are php.ini (the main PHP configuration file) and PHP-FPM (FastCGI Process Manager).
As a Linux administrator, you must understand and tune these settings for stability, speed, and efficient resource usage.
What is php.ini?
The php.ini
file is the main configuration file for PHP.
It controls how PHP behaves on the server: memory usage, upload size, error logging, session handling, and much more.
Common location of php.ini
in Rocky Linux 8:
/etc/php.ini
Important php.ini Parameters for Linux Admins
- memory_limit → Maximum memory a PHP script can use.
Example:memory_limit = 256M
(tune based on server RAM, avoid setting too high). - upload_max_filesize → Maximum file size allowed for uploads.
Example:upload_max_filesize = 64M
(good for WordPress media uploads). - post_max_size → Maximum size of POST requests (should be bigger than upload_max_filesize).
Example:post_max_size = 128M
- max_execution_time → Maximum time (in seconds) a script can run before being killed.
Example:max_execution_time = 300
(useful for big imports or backups). - max_input_time → Time limit for parsing input data.
Example:max_input_time = 60
- error_reporting and display_errors → For production servers, disable display of errors.
Example:display_errors = Off
,log_errors = On
- date.timezone → Set your server timezone.
Example:date.timezone = Asia/Kolkata
What is PHP-FPM?
PHP-FPM (FastCGI Process Manager) is a service that manages PHP processes efficiently.
Instead of running PHP as Apache module, PHP-FPM allows better performance, security, and process control.
It is especially important for high-traffic websites.
PHP-FPM service in Rocky Linux 8:
systemctl status php-fpm
PHP-FPM Configuration Files
- Main config file:
/etc/php-fpm.conf
- Pool configs (per website):
/etc/php-fpm.d/www.conf
Important PHP-FPM Parameters (www.conf)
- user and group → Should match Apache user (usually
apache
). - listen → Defines how PHP-FPM communicates with web server.
Default:listen = /run/php-fpm/www.sock
- pm → Process Manager.
pm = dynamic
→ Creates processes based on demand (best for most servers).pm.max_children
→ Maximum number of PHP processes (depends on RAM/CPU).pm.start_servers
→ Number of PHP processes created on start.pm.min_spare_servers
andpm.max_spare_servers
→ Keep enough idle workers for requests.
Tuning PHP-FPM (Best Practice)
Example tuning for a 4GB RAM server:
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
This ensures PHP does not consume more RAM than available and prevents crashes.
Monitoring PHP-FPM
Use these commands to monitor resource usage:
top -u apache
systemctl status php-fpm
tail -f /var/log/php-fpm/error.log
Best Practices for Linux Administrators
- Never set
memory_limit
orpm.max_children
higher than your available RAM. - Disable
display_errors
in production to avoid leaking sensitive info. - Use
log_errors
to troubleshoot PHP issues. - Set correct
date.timezone
to avoid application errors. - Always restart Apache and PHP-FPM after making changes.
Conclusion
The php.ini
file defines PHP behavior, while PHP-FPM
controls how PHP processes are managed.
By tuning these settings correctly, Linux administrators can ensure stable, secure, and high-performing PHP applications on Rocky Linux 8.
This knowledge is critical for running WordPress, e-commerce platforms, and enterprise applications.