We have some previous guides to optimize Apache2 and optimize Nginx with TLS and HTTP/2 (if you are interested about them, please use the searching this website feature). Here is first part on optimizing Apache 2.x with TLS HTTP/2. In this guide we will optimise general performance part, not TLS and HTTP/2. There are a variety tools that can assist in determining if the server admin needs to alter resource settings, like basic top command. Of course before we think about options like OCSP Stapling, we should make sure that normally the server is well tuned.
Optimizing Apache 2.x With TLS, HTTP/2 : Part 1
Actually we delivered some tips in our Apache2 HSTS server setup guide. We will not repeat them here. Those are normally altered during a standard post-installation. You need to open that old guide to check what very basic Apache2, PHP settings are not tuned in your setup. Apache does have own guide :
1 | http://httpd.apache.org/docs/2.2/misc/perf-tuning.html |
The most critical item to be taken into account for performance on Apache2 is the amount of hardware RAM allocated for each Apache process. What we have shown in that guide one was essentially optimizing mpm_prefork
(location is for Ubuntu, Debian) :
---
1 | cat /etc/apache2/mods-available/mpm_prefork.conf |
You must read the official document :
1 | https://httpd.apache.org/docs/2.4/mod/prefork.html |
In MPM Worker mode, Apache works more or less like Nginx. In MPM Prefork mode, Apache implements a non-threaded, pre-forking web server that handles requests in a manner similar to classical Apache server. Despite MPM worker probably more efficient than MPM prefork when the server is under heavy load, it is usually not installed that way because mod_php can not work with MPM worker.
We gave this example configuration :
1 2 3 4 5 6 7 | <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 20 MaxSpareServers 40 MaxRequestWorkers 256 MaxConnectionsPerChild 4500 </IfModule> |
You can increase StartServers to 8 to test. Apache2Buddy script reviews your Apache setup, and makes suggestions based on RAM. It is a basic program, focusing on the MaxClients directive, can be run through a single command:
1 | curl -L http://apache2buddy.pl/ | perl |
Next is KeepAlive
, which we are talking in the context of :
1 | /etc/apache2/apache2.conf |
This is one option to test :
1 2 3 4 5 6 7 | KeepAlive On KeepAliveTimeout 15 KeepAliveTimeout 2 MaxKeepAliveRequests 200 Timeout 40 EnableMMAP off EnableSendfile off |
this is another option to test :
1 2 3 4 5 6 7 | KeepAlive Off # KeepAliveTimeout 15 # KeepAliveTimeout 2 # MaxKeepAliveRequests 200 Timeout 40 EnableMMAP off EnableSendfile off |
Run configtest and restart Apache with each of them :
1 | systemctl restart apache2 |
Other things are optimized by WordPress W3 Total Cache Plugin like things via .htaccess
. That official guide from Apache we mentioned at the beginning is also helpful.