Support

Find answers, guides, and tutorials to supercharge your content delivery.

Apache Modules for Improving Performance

Updated on October 4, 2018
Apache Modules for Improving Performance

As the most widely used web server on the planet, Apache is known for its flexibility and dependability. Administrators have a lot of freedom in customizing their servers thanks to the hundreds of Apache modules available online. However, Apache comes with many pre-installed modules that you probably don’t need, and those modules could even be slowing down your application’s performance. This guide will cover the Apache modules you need as well as the ones you don’t so that you can optimize your server configuration and better serve your clients.

Picking the Right Multi-Processing Module

Multi-processing modules, or MPMs, extend Apache’s modular functionality in a number of ways. Most importantly, MPMs enable the use of children processes and threads to process client requests. You’ll have to choose an MPM when you first build your Apache server; which one you should pick depends on your server’s specific needs. While there are some platform-specific MPMs, you generally have three MPM options:

  • The worker MPM employs several child processes that each have multiple threads. The individual threads handle connections one-by-one. It is ideal for servers with high traffic since it can handle more concurrent connections using less RAM than other MPMs.
  • The event MPM is considered the default MPM for most Apache installations. Like the worker MPM, it creates multiple threads for each child process, but idle connections are handled by a single thread. Therefore, more threads remain available for new connections. The downside is that the event MPM isn’t compatible with Apache modules that aren’t thread-safe such as mod_php. Fortunately, you can sometimes get around such compatibility issues by using alternatives like PHP-FPM or mod_itk.
  • The prefork MPM also employs multiple child processes, but each one has just a single thread. Connections are handled one at a time. Thus, prefork uses more memory than the other MPMs, but it can be freely used with third-party Apache modules that are not thread-safe. The threadless design also makes debugging easier on some platforms.

If you’re working with an Apache server that has already been configured, you can see which MPM is installed by running the following code from your shell:

httpd -V
Source: Tecmint

Consult the official Apache docs for more information about MPMs and how to install them.

Apache Modules For Improving Performance

Now that you’ve settled on the best MPM for your situation, here is a list of optional Apache modules that can enhance your server’s performance:

1. mod_deflate and mod_brotli

The mod_deflate module allows Apache to compress your content with Gzip while mod_brotli allows you to compress it with Brotli compression (stronger). Using either method will result in smaller file sizes, which allows for quicker file transfers.

2. mod_disk_cache

Using mod_disk_cache is preferable to using mod_mem_cache since the latter doesn’t share its cache across different Apache processes. Try configuring mod_disk_cache with a flat hierarchy and placing your cache on a separate physical disk for best results. Remember that you must indicate when files should expire for caching to work.

3. mod_status

The mod_status Apache module doesn’t improve server performance by itself, but it gives you detailed information about incoming server connections. You can use such information to identify potential adjustments you can make to enhance user experience.

4. Passenger Module

If you’re using Rails, the passenger module allows processes to share memory and resources so that new application instances can spawn more quickly. When processes are no longer necessary, mod_passenger removes them.

5. Apache2Buddy

Apache2Buddy is technically a script, not a module. Like MySQLTuner, it evaluates your Apache configuration and suggests ways to make better use of RAM and process memory. Run it using this command:

curl -sL

Apache Modules That You Can Do Without

You’re probably not using all of the modules installed on your server. Stripping Apache down to just the modules you need can save a lot of memory and CPU consumption. Modules like mod_mime, mod_dir and mod_log_config are essential for most websites, but there are surely some modules you can do without.

If you’re using Ubuntu or Debian, you can get a full list of currently installed modules by typing the following from your shell:

apache2 -M

CentOS and Fedora users can do the same by entering:

httpd -M

Below are just a few of the default modules you can probably safely disable to enhance server performance:

authn_alias_module
authn_anon_module
authn_dbm_module
authn_default_module
authz_dbm_module
authz_default_module
authnz_ldap_module
cache_module
cgi_module
disk_cache_module
include_module
ldap_module
proxy_balancer_module
proxy_ftp_module
proxy_http_module
proxy_ajp_module
proxy_connect_module
suexec_module
version_module

Of course, before disabling any one of the modules above, do your research and determine if these modules are used in your environment. If they are, you should evaluate if the benefit from having the module enabled outweighs the cost of performance incurred.

As mentioned earlier, you should never use mod_php with a threaded MPM. Speaking of which, another way to improve performance is to disable safe_mode for PHP since it can account for 50-70 percent of your script time.

If your modules were built as DSOs, then you can turn them off by commenting out the appropriate LoadModule directive. For modules that are statically linked to your Apache binary, you’ll have to recompile Apache.

Summary

Of course, there are other factors that can cause your Apache server performance to suffer besides its configuration. Nonetheless, choosing the right modules from the beginning will leave you better prepared to deal with other issues down the road.

Supercharge your content delivery 🚀

Try KeyCDN with a free 30 day trial, no credit card required.

Get started