PHP-FPM (FastCGI Process Manager) provides a fast interface between PHP and web servers like Nginx. This guide explains how to install, configure, and tune PHP 8.3-FPM for production use with Nginx on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- Nginx installed
- A user with sudo privileges
Step 1 – Install PHP 8.3-FPM
Install the FPM package:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.3-fpm -y
Step 2 – Start and Enable PHP-FPM
Start the service:
sudo systemctl start php8.3-fpm
sudo systemctl enable php8.3-fpm
Step 3 – Verify the Socket Exists
Confirm the Unix socket is created:
ls -la /var/run/php/php8.3-fpm.sock
Step 4 – Configure PHP-FPM Pool
Edit the default pool configuration:
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
Key settings to tune for production:
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 8
pm.max_requests = 500
Step 5 – Configure Nginx to Use PHP-FPM
In your Nginx server block:
location ~ .php$ {
try_files $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Step 6 – Test the Configuration
Verify Nginx and PHP-FPM configs:
sudo php-fpm8.3 -t
sudo nginx -t
Reload both services:
sudo systemctl reload php8.3-fpm
sudo systemctl reload nginx
Step 7 – Enable OPcache
OPcache dramatically improves PHP performance by caching compiled bytecode:
sudo nano /etc/php/8.3/fpm/php.ini
Set:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
Conclusion
PHP 8.3-FPM is now correctly configured with Nginx on Ubuntu 24.04 LTS. Dynamic process management balances performance and resource usage — monitor with php-fpm8.3 -tt and adjust pool settings as traffic grows.