1️⃣ What PHP-FPM Actually Is
PHP-FPM is a process manager for PHP that handles PHP execution for web servers.
Important point:
> Web servers like Nginx cannot execute PHP directly.
So they send PHP requests to PHP-FPM, which runs the PHP code and returns the result.
2️⃣ Why PHP-FPM Exists
Older PHP setups used mod_php with Apache HTTP Server.
Problems with mod_php:
PHP-FPM solves this by managing PHP workers efficiently.
# 3️⃣ How PHP-FPM Works
Request Flow
Browser Request
│
▼
Nginx Web Server
│
▼
FastCGI Request
│
▼
PHP-FPM Worker Process
│
▼
Execute PHP Script
│
▼
Return Response → Nginx → BrowserExample request:
http://example.com/index.phpFlow:
Nginx → PHP-FPM → index.php → HTML Output# 4️⃣ PHP-FPM Architecture
PHP-FPM works using a master process + worker processes.
PHP-FPM Master Process
│
├── Worker 1
├── Worker 2
├── Worker 3
└── Worker 4Master Process
Responsible for:
Worker Processes
Responsible for:
# 5️⃣ Process Management Modes
In the PHP-FPM config (www.conf) you will see:
pm = dynamicThere are 3 modes.
1️⃣ Static Mode
Fixed number of workers.
pm = static
pm.max_children = 10Meaning:
10 PHP processes always runningGood for predictable workloads.
2️⃣ Dynamic Mode (Most Common)
Workers are created based on demand.
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 10Meaning:
Start with 5 workers
Minimum idle = 3
Maximum idle = 10Best for most production servers.
3️⃣ On-Demand Mode
Workers start only when request arrives.
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 10sGood for low traffic servers.
# 6️⃣ Unix Socket vs TCP
PHP-FPM can communicate with Nginx in two ways.
TCP Connection
127.0.0.1:9000Example config:
fastcgi_pass 127.0.0.1:9000;Pros:
Cons:
Unix Socket (Recommended)
/run/php-fpm/www.sockExample config:
fastcgi_pass unix:/run/php-fpm/www.sock;Pros:
# 7️⃣ PHP-FPM Pools
PHP-FPM supports multiple pools.
A pool is a group of PHP workers with its own settings.
Example:
/etc/php-fpm.d/www.confExample pool:
[website1]
user = nginx
group = nginx
listen = /run/php-fpm-site1.sockThis allows:
Site1 → PHP Pool1
Site2 → PHP Pool2Benefits:
# 8️⃣ Important PHP-FPM Files
# 9️⃣ Check PHP-FPM Status
Check service:
systemctl status php-fpmCheck running processes:
ps aux |grep php-fpmCheck socket:
ls /run/php-fpm/# 🔟 Real Production Architecture
Modern architecture often looks like this:
Internet
│
▼
Nginx Load Balancer
│
▼
Nginx Web Server
│
▼
PHP-FPM
│
▼
PHP Application
│
▼
Database ServerDatabase example:
# 🧠 Why DevOps Engineers Care About PHP-FPM
Because you must tune:
This directly affects:
✅ Simple summary
PHP-FPM is:
> A process manager that executes PHP scripts and communicates with web servers through FastCGI.