Here is a complete article explaining the Apache Prefork MPM configuration, focusing on each directive and its impact on performance:
⚙️ Understanding Apache Prefork MPM Configuration for Optimal Server Performance
The Prefork MPM (Multi-Processing Module) is one of the oldest and most stable ways Apache handles requests. It creates multiple child processes with one thread each, isolating them for safety and compatibility — especially with non-thread-safe libraries like some older PHP versions.
In this guide, we’ll break down the key directives:
# prefork MPM
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
We’ll explain what each does and how you can tune them for the best performance.
What is Prefork MPM?
Apache supports several MPMs (like event
, worker
, prefork
), and Prefork handles each request in its own process. There’s no sharing between requests, making it very stable and secure — ideal for:
️ Breakdown of Key Directives
StartServers
StartServers 5
Tip: Set higher if you expect instant traffic after reboot (e.g., busy sites).
MinSpareServers
MinSpareServers 5
Tip: Prevents delays under bursty traffic. Don’t set too low.
MaxSpareServers
MaxSpareServers 10
Tip: Helps control memory usage during low activity periods.
MaxRequestWorkers
(formerly MaxClients
)
MaxRequestWorkers 150
The maximum number of simultaneous requests Apache will handle.
If all slots are used, new requests are queued until one becomes free.
Tip: This directly affects site concurrency and resource usage.
Set based on your available RAM, PHP memory limit, and average request size.
Formula:
MaxRequestWorkers = Total RAM available for Apache / Memory per process
Example:
If each Apache process uses ~30MB and you have 4GB RAM for Apache:
4096 MB / 30 MB = ~136
, so 150 is reasonable.
MaxConnectionsPerChild
MaxConnectionsPerChild 0
Tip: Helps prevent memory leaks in long-running processes.
Set to a high number (e.g., 1000–10000) in production.
Example Use Case: Busy WordPress Site
StartServers 10
MinSpareServers 10
MaxSpareServers 20
MaxRequestWorkers 200
MaxConnectionsPerChild 5000
Why:
Higher spare servers for sudden traffic spikes
Reasonable limit on MaxRequestWorkers to avoid memory overload
Rotating processes to avoid leaks
How to Check Active MPM?
Run this command:
apachectl -V | grep MPM
You should see:
Server MPM: prefork
If not, you can switch with:
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo systemctl restart apache2
⚠️ Performance Considerations
Prefork is not ideal for very high concurrency or modern async apps.
Each connection = 1 process = 1 chunk of RAM.
For better performance under high load, consider switching to MPM Event or using PHP-FPM with Worker MPM.
✅ Summary: Recommended Defaults for Prefork MPM
Directive | Recommended |
---|
StartServers | 5–10 |
MinSpareServers | 5–10 |
MaxSpareServers | 10–20 |
MaxRequestWorkers | Depends on RAM (100–300) |
MaxConnectionsPerChild | 1000–10000 or 0 for unlimited |
Conclusion
Apache’s Prefork MPM is a solid, stable choice for traditional PHP applications. Tuning the settings like MaxRequestWorkers
and StartServers
helps you strike a balance between performance, memory usage, and reliability.
While newer MPMs like event
offer better performance in modern setups, Prefork remains relevant when thread safety is required — especially on shared hosting or legacy systems.