10

I have a Xen virtual private server (VPS) running Ubuntu 8.10, with 128M RAM.

I've found several "how to optimize Apache and MySQL for low-memory VPS" pages via Google, but they provide contradictory information. So I'm asking Server Fault: how does one optimize Apache and MySQL for a low-memory VPS configuration?


A couple of people have suggested using nginx instead of Apache. I'll look into that, but I'd prefer to stick with Apache if possible, just to avoid having to learn all about configuring application stacks on top of an unfamiliar (to me) web server.

Kristopher Johnson
  • 315
  • 1
  • 6
  • 12

3 Answers3

7

Nginx is great, but if you want to stick with Apache, it's possible to slim it down quite a bit from the default settings:

  • Use the worker MPM rather than prefork (with worker MPM Apache no longer has a "process per connection" model).
  • Look at all the shared modules you're loading, get rid of any that you don't need.
  • Avoid embedding application servers inside Apache (i.e. mod_python, mod_php, etc) if you can avoid it. Instead, run application servers in a separate process and have Apache proxy to them (i.e. for Python code use mod_wsgi in daemon mode). This way your Apache threads that are simply serving static content won't be unnecessarily bloated.
  • In your Apache config, reduce the StartServers, MaxClients, MinSpareThreads, and MaxSpareThreads settings. Depending on your expected load you can sometimes reduce them by a factor of five or more from the default settings.
Carl Meyer
  • 196
  • 1
  • 3
2

If you have memory constraints, I would recommend using nginx as an alternative if at all possible. It consumes much less memory than Apache and depending on your needs could be all that you need.

As a bonus, nginx tends to be significantly faster than Apache. =)

Jauder Ho
  • 5,337
  • 2
  • 18
  • 17
2

Ditch apache, it's process per connection model will not play will with your low memory VPS.

I suggest nginx as a replacement.

Dave Cheney
  • 18,307
  • 7
  • 48
  • 56