Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How to minimize memory usage on LAMP? Virtual dedicated server, max 512 RAM, 20 GB drive space, it should run a Wordpress blog. Not sure for load, but lets say 2-5k visitors per day.

share|improve this question
2  
I love LAMP. I love LAMP –  Chopper3 May 10 '09 at 20:09
    
Chopper3, are you just looking at things on ServerFault and saying that you love them? –  Kyle Cronin May 15 '09 at 18:36

5 Answers 5

If you're really into memory saving, you'd probably be better of replacing LAMP (Linux, Apache, MySQL, PHP) with LLMP (LigHTTPd instead of Apache) or even better LLSP (Linux, LigHTTPd, SQLite and PHP).

share|improve this answer

At a maximum of 5k hits a day, that works out to just one query every 10 seconds. Not a huge load. Although RAM is the constraining factor, you can probably get away with beefing it up with swap, given the very low volume of traffic you are expecting.

Still, trimming out some fat will go a long ways towards your goals. I've done some work with low-memory servers, but that was a long time ago. I'll try my best to remember. Here it goes:

  • The trick here is to minimize the amount of resident program usage. Each program not only takes up RAM to store code, but it also consumes other resources.

  • I would first look at removing any unneeded ttys from /etc/inittab, by remarking them out with a hash (#). That frees up a half-meg or so. Two consoles should be enough (the spare is there in case your shell becomes unresponsive on the other one - be sure to log both in when doing work, that way an unresponsive system won't lock you out during heavy swapping/loading, etc.)

  • Find every single service you won't be using, and configure them to not start on reboot (unless it is required by something else). This would be good practice anyway for a server that is public-facing, as it also reduces your attack surface.

  • If possible, try to migrate services to inetd/xinetd, or some other superserver, which will in turn free up memory from being used by the "resident in memory" model mentioned above.

  • Given a 20Gb drive, it's highly unlikely you'll have extensive data sets to publish out via your database backend. Look at giving your database just enough RAM to answer 2 simultaneous queries, while handling 3 simultaneous interconnects.

  • If you have GDM/KDM/XDM/whatever login manager starting on startup, turn it off! The secondary resources it requires will just end up clogging your swapfile, and consuming precious RAM. Do all of your work through SSH, or though any administrative webpages that you can get to with a browser.

  • If you just have to have a graphical session, look into setting up VNC as a remote desktop service. It will only allocate memory when there is an active session. Do not expose the VNC service to the outside, you will be asking for trouble.

share|improve this answer
up vote 1 down vote accepted

This link has more information, than all received answers together:)

http://wiki.vpslink.com/Low_memory_MySQL_/_Apache_configurations

share|improve this answer

Don't run X, shutdown all unneccesary services, and compile Apache, MySQL, and PHP with only essential functionality.

share|improve this answer

For trimming apache itself, look at the modules that you are loading. There are some good other answers on here for general memory and load reductions so take those into account as well. It's hard to know exactly what would be good to turn off but a few recommendations I would make are:

*auth_digest_module* - most browsers don't support this form of authentication so it is unlikely you would be using it.

*ldap_module*, *authnz_ldap_module* - if your not authenticating against ldap or anything based off of ldap these aren't needed. Note: PHP might depend on this if your using it's ldap functions. I've never tried turning these off when I was using those functions.

*userdir_module* - this might already be turned off and should be on any production website anyway

*speling_module* - this one is tricky. If you turn this off your url's are case sensitive. Supposedly this also "corrects misspelled urls" though I've yet to see this actually happen. If your client-base types in the urls, I would leave this on otherwise it's probably safe to turn off.

Apache has a lot of documentation on their modules. I would recommend going through it and after reading the documentation on a modules decide if you need it but only if you completely understand the module. Some of them provide very important core functionality and can break other things by not being available.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.