Apache HTTP server or just Apache as it is commonly called is the most widely used web server, hosting about half of all the websites on Internet. The cross platform web server is developed and maintained by an open community of developers under the guidance of Apache Software Foundation which is a non-profit corporation whose membership is based on meritocracy.

Apache’s popularity is result of it being a free to use software which requires minimal configuration and administration. This same flexibility and ease of use is what makes it sluggish and gobble up a lot of memory, resulting in much slower performance than it is capable of. So here are some easy tips to help you enhance the performance of your web server.

Read Also:

How to install Apache, MariaDB and PHP (LAMP) on Ubuntu

How to Install LAMP Server on Centos 7

How To Optimize Apache Web Server Performance

1) Keep your Apache updated to its latest version and use a kernel older than 2.4

The simplest and best way to enhance the performance is to keep the software updated. The regular updates fixes bugs and improves performance of the software as they are made available. Kernel versions above 2.4 have sendfile kernel system call enabled by default which results in faster network file transfer while using less memory.

2) Load only the required modules

In Apache functions are loaded in the server by selecting a set of modules. These modules are of two types; static and dynamic.

Generally there are much more modules loaded than you might be using. The best way to go about it is to unload the modules available one by one and then restarting Apache after each unload. If any error occurs after unloading a module then we can just reload that module.

Command to unload a module –  ‘sudo a2dismod <name-of-module>’                 Command to load a module –     ‘sudo a2enmod <name-of-module>’

*Commands are for Debian & other Debian-based distros including Ubuntu

3) Using proper MPM configuration

Multiple processing modules (MPM) are responsible for handling web server connections that come to the server. They decide how to bind network ports on the machine, accept requests and dispatch children to handle the request. MPMs are of two types Prefork and Worker.

Apache configurations by default ship in with Prefork MPM which is slower than Worker MPM. Switching to Prefork MPM will let us handle more traffic while using less memory.

Command to enable Worker module- ‘a2enmod mpm_worker’                                 Command to disable Prefork module- ‘a2dismod mpm_prefork’

*Commands are for Debian & other Debian-based distros including Ubuntu

4) Setting ‘MaxRequestWorkers’

By setting limit on greatest number of simultaneous connections to a server one tries to stop swapping of connections. The limit set should be ideal to the memory available and expected traffic. If limit is set too low then very few connections to the server will be established and memory will remain underutilised. If limit is set too high then server will start swapping connections thus drastically increasing the load time of web pages.

You can place this Limit inside /etc/httpd/conf/httpd.conf or /etc/apache2/apache2.conf depending on whether you are using CentOS or Debian.

5) Setting ‘Timeout’

Setting of Timeout decides how long to wait for the next request from the connection. In a busy server it should be set for a shorter duration so that the available resources are not wasted just waiting for a new request from the client.

6) Use compression and caching

Compressing content requested by client before sending it can reduce the load on your server. The clients browser automatically decompresses the content on his side. Compression of content is done by module-mod_gzip or mod_deflate.

Caching refers to process of storage of data in cache. A web page stores cache on clients hard disk so that when he requests the same data again then the browser gets the data from the stored cache instead from original server thus saving time and reducing the load on the server. The simplest caching strategy is ‘File caching’. It opens files or file descriptors when Apache starts, though it doesn’t respond to any change in the file system and only handles static files nonetheless it reduces workload on slow servers considerably.

Caching is done by mod_file_cache module. It can be enabled in Ubuntu by                 ‘sudo a2enmod file_cache’

7) DNS Enquiries

Hostnamelookups should be deactivated to stop the server from starting a DNS lookup for the originating IP address each time the client sends a request. Doing so would take some load off the servers which have space constraints.

 8) KeepAlive Requests

The KeepAlive feature allows multiple requests from same TCP connections. The web browser and web server uses the same connection which reduces latency and CPU usage.The use of this feature though is recommended only if you have enough RAM but a limiting CPU, this is because connections have to be kept open while it waits for new requests from the client this open connection occupies space in the RAM. This feature is also recommended to be turned on if the website has a lot of images and other files linked to it or if it has traffic which is evenly distributed over the day instead of a lot of user accessing it in a short period. Otherwise it is best to disable this feature to get better performance.

Implementing these eight tips can drastically boost the performance of your Apache web server.