Series: WordPress Performance on DirectAdmin (Rocky Linux 9)
Phase 5: Apache & Server Layer — Part 17 of 30
Apache Performance Tuning for WordPress on DirectAdmin
Optimizing Apache for WordPress on DirectAdmin (Rocky Linux 9) requires a methodical approach that accounts for DirectAdmin’s configuration templates, PHP-FPM pool handling, and per-domain flexibility. This article provides practical steps and recommendations for sysadmins aiming to improve throughput and reduce latency at the server layer, with a focus on safe, reproducible changes.
Overview: Apache on DirectAdmin
DirectAdmin typically deploys Apache in one of two configurations on Rocky Linux 9: as a standalone web server, or as a backend behind NGINX (reverse proxy mode). PHP execution is handled by PHP-FPM pools, with per-domain pools enabled by default. All tuning assumes you are working within DirectAdmin’s configuration management—direct edits to Apache or PHP configs outside the panel’s templates may be overwritten by updates or rebuilds.
Preparation and Safety
- Backup all active Apache and DirectAdmin configs before making changes.
- Test changes in a staging environment first.
- Restarting Apache can cause brief downtime. Plan maintenance windows for production.
- Monitor resource usage and error logs after each change.
Check Current Apache Environment
sudo apachectl -V
sudo apachectl -M
sudo systemctl status httpd
These commands confirm version, loaded modules, and service status. Verify you’re running a recent Apache 2.4.x release (DirectAdmin/EL9 default).
Step 1: Identify and Edit the Correct Template
DirectAdmin manages Apache configs via templates (under /usr/local/directadmin/data/templates/). To apply global changes, copy and customize the relevant templates:
sudo cp /usr/local/directadmin/data/templates/httpd.conf /usr/local/directadmin/data/templates/custom/
sudo cp /usr/local/directadmin/data/templates/httpd-php-fpm.conf /usr/local/directadmin/data/templates/custom/
Edit only the files in custom/; these persist through DirectAdmin updates. For per-domain overrides, use the panel’s “Custom HTTPD Configurations.”
Step 2: Optimize Apache MPM Settings
DirectAdmin on EL9 defaults to event MPM (recommended). To check:
sudo grep -i mpm /etc/httpd/conf.modules.d/00-mpm.conf
To adjust worker counts, edit /etc/httpd/conf.modules.d/00-mpm.conf:
sudo vi /etc/httpd/conf.modules.d/00-mpm.conf
Good starting values for a 2-core/4GB VM:
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
For larger servers, scale MaxRequestWorkers upward. For sites with high concurrency, increase ThreadsPerChild and MaxRequestWorkers, but monitor memory consumption closely.
Apply and Test
sudo systemctl reload httpd
Test with a load generator (e.g., wrk):
wrk -t4 -c100 -d30s https://yourdomain.com/
Observe CPU and memory usage:
top -p $(pgrep -d',' httpd)
Step 3: Tune KeepAlive and Timeout
Persistent connections reduce handshake overhead but can tie up workers. In /etc/httpd/conf/httpd.conf (or the custom template):
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2
Timeout 30
A KeepAliveTimeout of 2–3s is usually sufficient for WordPress. Lowering Timeout to 30s helps avoid stuck connections.
Step 4: Disable Unused Apache Modules
Each loaded module consumes memory and may impact performance. List enabled modules:
sudo apachectl -M
Comment out unneeded modules in /etc/httpd/conf.modules.d/*.conf. Typical modules safe to disable for WordPress:
mod_status(unless used for monitoring)mod_cgiandmod_cgid(not needed for PHP-FPM)mod_autoindex(unless directory listing is required)
After changes:
sudo systemctl restart httpd
Warning: Restarting Apache will cause a brief service interruption.
Step 5: Leverage HTTP Compression and Caching
Enable mod_deflate for gzip compression and mod_expires for static asset caching. In DirectAdmin, add these to your custom template or per-domain HTTPD config:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresDefault "access plus 1 day"
</IfModule>
After editing, rebuild configs if needed:
sudo /usr/local/directadmin/custombuild/build rewrite_confs
Step 6: Adjust Logging for Performance
High-volume logging can impact disk I/O. In production, set LogLevel to warn or lower in the custom template:
LogLevel warn
Rotate logs regularly (DirectAdmin uses logrotate under EL9):
sudo logrotate -vf /etc/logrotate.d/httpd
Step 7: Secure and Harden Apache
Disable ServerSignature and ServerTokens in your template:
ServerSignature Off
ServerTokens Prod
Further hardening is covered in later phases of this series.
Step 8: Test WordPress Responsiveness
After each tuning step, use WP-CLI and HTTP tools to confirm WordPress is operational:
cd /home/USERNAME/domains/yourdomain.com/public_html
wp core is-installed
curl -I https://yourdomain.com/
Monitor Apache and PHP-FPM logs:
sudo tail -f /var/log/httpd/error_log /var/log/php-fpm/www-error.log
Step 9: Per-Domain Apache Overrides
If certain WordPress sites are busier, use DirectAdmin’s “Custom HTTPD Configurations” (panel) to set per-domain overrides (e.g., custom caching rules, overrides for Timeout). Changes here are preserved and do not affect global settings.
Step 10: Review Firewall and SELinux Settings
Ensure Apache is allowed through the firewall and SELinux is not blocking web traffic:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo setsebool -P httpd_can_network_connect 1
Check SELinux denials with:
sudo ausearch -m avc -c httpd
Quick Checklist
- Backup Apache and template configs.
- Edit DirectAdmin custom templates, not system files.
- Use event MPM and tune worker counts for your hardware.
- Reduce KeepAliveTimeout and Timeout values.
- Disable unused modules.
- Enable compression and static asset caching.
- Lower log verbosity; ensure logrotation is working.
- Test each change with WP-CLI and HTTP tools.
- Apply per-domain overrides for high-traffic WordPress sites.
- Update firewall and SELinux policies as needed.
Conclusion
Apache’s performance for WordPress on DirectAdmin (Rocky Linux 9) can be significantly improved with targeted MPM tuning, connection management, and careful module selection. Always use DirectAdmin’s configuration templates to ensure changes persist across updates. After each adjustment, validate with WP-CLI, load-testing tools, and system logs. For further optimization, see later phases in this series on PHP-FPM, reverse proxy, and edge caching strategies.
Note: This article offers general technical guidance. Validate all configurations in a safe environment before applying them to production.
Previous: How to Monitor and Debug Long-Running WordPress Cron Jobs
Next: Understanding .htaccess Performance Rules for WordPress

