How To Reduce RAM Usage on your Apache VPS

Apache can use a lot of RAM especially if you are running WordPress websites on your server. Over the years I have had many occasions of MySQL crashing due to running out of RAM which then takes all your sites down. After many frustrated evenings of research I found this simple method to reduce RAM usage.

The method is to turn off the Apache KeepAlive setting. By default, this is set to on.

What does the Keepalive setting do?

The Keepalive setting, when set to on, keeps processes running even when idle. This is instead of creating new processes. This can help to improve performance but comes at the cost of using additional memory.

How to turn off Keepalive

The basic commands for Debian are below. If you are running a different distribution you will need to alter accordingly.

  • cd /etc
  • cd apache2
  • sudo nano apache2.conf

Edit the KeepAlive On and change to Off

Note: This may cause your server to use additional CPU.

The proper solution (vs trying to reduce RAM usage) would be to add more RAM however I have found that it gets out of hand as often the high RAM usage is caused not by genuine visitors but bots or spammers.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.