Configuring a lightweight Apache / MySQL install on Debian/Ubuntu
I’m going to explain how to setup a lightweight Apache and MySQL to work on a smaller server such as SliceHost’s 256mb VPS. This will work on both Debian and Ubuntu servers. You are going to install Apache 2 and MySQL like you normally would. After you install it, we are going to edit the config files to better utilize your available memory. To do this you need to be logged in via SSH to your server.
First enter:
Look for the MySQL command. (If you don’t see it, press <Shift> + M to sort by the amount of memory used) Once you locate MySQL, make note of the percentage of memory it is using. Now exit top by hitting ‘q’.
We are now going to edit your MySQL configuration. First you want to make a backup by entering:
Now open my.cnf using your preferred editor. We will use nano for this tutorial.
Find the following line in your my.cnf file:
Uncomment that line. (Note: if after changing this line your database no longer works, come back and comment this line out again and restart MySQL.)
Next locate the line:
and add:
below it. Next find the section labeled Fine Tuning. Change the settings in that section to match:
max_allowed_packet = 1M
thread_stack = 64K
thread_cache_size = 4
sort_buffer = 64K
net_buffer_length = 2K
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
Now restart MySQL:
Now run ‘top’ again, and see what your percentage of memory is. If all is right, it should be much lower. Now we will change the apache configuration. This will not show you a lower memory usage per se, however, it should prevent apache from using too much memory. First lets make a backup of your apache config.
Now lets open the apache config file for editing:
Now make your entries match the following:
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 3
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 30
MaxRequestsPerChild 2000
</IfModule>
Finally restart apache:
If you have problems with memory still, try lowering your “MaxClients” to 25.
This setup should work on most Debian and Ubuntu VPS’s. Note that your results may very. If you have any questions, or need help, feel free to post a comment and I will try to get back to you.










Chris, after following the directions and even disabling most of the plugins, as discussed in the SH chatroom (only Akismet and WP Stats were enabled), the free memory still hovered around 30-35MB.
I then re-enabled WP Super Cache, and the free memory still hovered around 30-40MB. Now I see that it’s stabilized around 70-100MB or so.
I’ll still need to re-enable some of my plugins, so I’ll keep monitoring the free memory to see when it tanks. Still not sure myself where the problems lie, but I’ll keep looking at it.
Thanks for your help!
I gave up this morning and upgraded to the 512MB slice.
My sites were down again, and this with only three plugins enabled: Akismet, WP Stats and WP Super Cache. I don’t know, maybe I’m getting more traffic than your sites and I don’t know it. I don’t count search engines when I look at the traffic. All bots and crawlers are excluded, and I only look at people.
At any rate, my sites are doing great now, even while getting crawled by search engines, and free memory is around 270MB, which is a lot better than 20-30MB or less.
I did leave your tuning config in there. I may up some parameters if the need arises, but my slice is doing great for now. NO DOWNTIME! Yes!
[...] got it back up and re-tuned Apache and MySQL with Chris Johnston’s help, but at some point during the night, it went down hard, and stayed down. When I woke, [...]
[...] has an excellent post on configuration parameters for Apache and MySQL to help save memory. This was specifically used be [...]
[...] Configuring a lightweight Apache / MySQL install on Debian/Ubuntu | Chris Johnston I’m going to explain how to setup a lightweight Apache and MySQL to work on a smaller server such as SliceHost’s 256mb VPS. This will work on both Debian and Ubuntu servers. (tags: performance mysql hosting slicehost) [...]
Thanks for this, it’s proved really handy. Do you know much about the query_cache_size and query_cache_limit parameters? To be honest I’m not really too familiar with the mysql query cache but reducing these seemed to free up a fair bit of memory.
Hello! Chris could u tell me hwo i can set up a web mail? pls help me. Thank you.
I have never setup web mail, or any sort of eMail for that matter, but it may be something for a future article.
Following the instructions for mysql on a mysql5/debian install i raised memory usage by 5% on idle..
I guess the most comes from skipping innoDB. Unfortunatly i need innodb because my rows change alot.
Just to let you know. Bye
[...] That is it.. Your LLMP install is now complete! Stay tuned for more articles on how to setup your websites using Lighttpd as your web server. Because MySQL does not come optimized, please follow the MySQL part of the tutorial on Configuring a lightweight Apache / MySQL install on Debian/Ubuntu. [...]
Thanks for the tips. They helped a lot, but it may be that 128 MB just isn’t enough RAM for WordPress. I may have to upgrade.
@Dan Jones Probably not.. I would try either Nginx or Lighttpd.. Or take a look at Mosso and Slicehost for a better VPS.
Thank you so much for this tutorial It has made all the difference on the performance of my slicehost apache2/MySQL installation. A quick question: what do you think about creating a tmpfs with these commands and would it be detrimental to a slicehost 256 VPS?
mkdir -p /my/home/directory/ramdrive
mount -t tmpfs -o size=500M,mode=0777 tmpfs /my/home/directory/ramdrive
Then pointing the tmp directory in my.cnf to the ramdrive?
Thank you.
Thanks for the great article. I use it as a starting place for every slice I generate.
Cheers,
~e
Thanks for the tips. I have a staging server running on a teeny weeny 128MB slice that was performing very poorly.
It is now quite snappy. It is a good low traffic environment to optimise in this way. I am guessing these settings cease to be as optimal for a busy slice (no such thing as a free lunch).
The slicehost article add some details for some of these settings and might be useful for someone.
http://articles.slicehost.com/2008/4/28/ubuntu-hardy-apache-configuration-1
Thanks again
[...] Configuring a lightweight Apache / MySQL install on Debian/Ubuntu | chrisjohnston.org (tags: apache config tips) « links for 2009-12-02 | [...]
This is a great article. It has significantly reduced the amount of RAM required to run both MySQL and Apache. I’ll let you know if the VPS lockups continue to seize
[...] posts related to MySQL optimization including a conversation on Stack Overflow, explanation on a lightweight configuration on Debian, and a lengthy WordPress optimization tutorial. I also came across a forum thread on WordPress.org [...]
[...] get some kind of kickback. I don’t even know how much it is. [↩]Take a look at “Configuring a Lightweight Apache / MySQL Install on Debian / Ubuntu” and “Introducing LAMP Tuning Techniques” via this thread on Slicehost’s [...]
Great tips, but I’m wondering if this is valid for all kind of apps running. I have to optimize my server for an open source crm application, vtiger crm, running on php/mysql.
right now the apache process is taking close to 50MB per process, which I hope to reduce down to 20MB. Its standard installation on Centos 5.4 (including running tomcat, which I don’t require), but I’m afraid how to remove extra packages, without affecting my running application.
any help will be highly appreciated.
regards,
Deep
This was great – Could you mention what the downsides are?
I have yet to run into any downsides.
Thanks for the steps.
the free memory of my VPS increased from 3-5 to 150 MB!
nice!
I hope there aren’t huge drawbacks when I am hit with a huge load of traffic.
Oh, forgot to ask has anybody experienced any issues with the settings in this article when the traffic of your site has increased ?
First enter:Look for the MySQL command. (If you don
I have overwritten my.cnf with a wrong one.
How may I rebuild it? I do not know what are the right path of all the service… I’m using a VPS CentOS 5 a MySQL 5.0.9. May amyone help me?
here is a copy of mine:
[mysqld]
default-storage-engine = myisam
key_buffer = 8M
query_cache_size = 8M
query_cache_limit = 4M
max_connections=25
thread_cache=1
skip-innodb
query_cache_min_res_unit=0
tmp_table_size = 4M
max_heap_table_size = 4M
table_cache=256
concurrent_insert=2
give it a go and ignore any errors you get during start up it still works for me…
“Oh, forgot to ask has anybody experienced any issues with the settings in this article when the traffic of your site has increased ?”
i know the owner of freevps.us (i think about 100k of hits per month)
he uses the mysql setting i posted above but he runs nginx and he keeps his server at under 55MB.
whatever is described in article : tried by me and still my apache consuming all of memory. each connection is taking at least 30mb.
i am looking to move to nginix. ca you help me convert .htaccess to nginx one?
Leave your response!
About Chris
Social Media
Recent Comments
Most Commented
Most Viewed