
How to Optimize Apache Web Server Performance on Linux Servers
The Apache HTTP Server is one of the most widely used web servers in the world—known for its stability, flexibility, and extensive module ecosystem. However, as traffic grows and application demands increase, default settings may no longer be sufficient.
In this guide, we’ll show you how to optimize Apache web server performance on Linux systems (including Ubuntu, Debian, CentOS, and Arch) by tweaking key settings, enabling useful modules, and applying best practices.
✅ Why Optimize Apache?
Without optimization, Apache may:
- Use more memory than necessary
- Serve requests slower
- Crash under high load
- Struggle with concurrency
Proper tuning can lead to:
- Faster page load times
- Lower CPU and RAM usage
- Higher concurrent request handling
- Better scalability
Step 1: Choose the Right MPM (Multi-Processing Module)
Apache supports several MPMs, each suited for different scenarios:
prefork
: Non-threaded, stable, ideal for compatibility (e.g., with PHP CGI)worker
: Threaded, better performance thanprefork
event
: Best for high concurrency; non-blocking I/O
On Debian/Ubuntu, check and enable event
MPM:
bashCopyEditsudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo systemctl restart apache2
For PHP users: consider switching to PHP-FPM for compatibility with
event
.
Step 2: Adjust Apache’s Global Settings
Open Apache config file:
bashCopyEditsudo nano /etc/apache2/apache2.conf
Or on CentOS:
bashCopyEditsudo nano /etc/httpd/conf/httpd.conf
Recommended changes:
apacheCopyEditKeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2
Timeout 30
- KeepAlive: Enables persistent connections for speed
- Timeout: Reducing this saves memory and resources
Step 3: Tune MPM Parameters
Edit MPM config (Ubuntu example):
bashCopyEditsudo nano /etc/apache2/mods-available/mpm_event.conf
Example values for 2GB RAM server:
apacheCopyEditStartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
Tip: Adjust
MaxRequestWorkers
based on your RAM and expected traffic.
Step 4: Enable Compression and Caching
Enable mod_deflate
for GZIP Compression:
bashCopyEditsudo a2enmod deflate
Then add this to Apache config or .htaccess
:
apacheCopyEdit<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
</IfModule>
Enable mod_expires
for Browser Caching:
bashCopyEditsudo a2enmod expires
Sample config:
apacheCopyEdit<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
</IfModule>
Step 5: Disable Unused Apache Modules
List enabled modules:
bashCopyEditapache2ctl -M
Disable unnecessary ones:
bashCopyEditsudo a2dismod status autoindex negotiation
sudo systemctl restart apache2
Fewer modules = faster server start + less memory usage.
Step 6: Use HTTP/2 (Optional but Recommended)
If you’re using HTTPS (which you should), enable HTTP/2 for better performance:
bashCopyEditsudo a2enmod http2
In your virtual host config:
apacheCopyEditProtocols h2 http/1.1
Then restart Apache.
Step 7: Monitor Performance
Use tools like:
htop
,top
– system usageapachetop
– real-time Apache statsab
(ApacheBench) orwrk
– load testingmod_status
– internal monitoring endpoint
Enable mod_status if needed:
bashCopyEditsudo a2enmod status
🔐 Bonus Tip: Use a Reverse Proxy or CDN
For high-traffic environments:
- Place Nginx as a reverse proxy in front of Apache
- Use Cloudflare or another CDN for caching, SSL, and DDoS protection
Summary
By default, Apache is built for compatibility—not performance. With a few strategic changes, you can drastically boost speed, reduce resource usage, and serve more users effectively.
Need High-Performance Hosting?
At GreenHost, we optimize and manage Apache servers for you. Whether you’re running a blog, ecommerce platform, or LMS — our eco-friendly Linux hosting delivers fast, secure, and scalable performance.