Featured Post

Installing Ubuntu 9.04 Desktop

We are going to go over how to install Ubuntu 9.04 Jaunty Jackalope onto your computer. 1. Creating bootable media Download the software and create in installation disk. You can download Ubuntu 9.04 from http://www.ubuntu.com/getubuntu/download After downloading Ubuntu, create an install CD. 2. The Installation First...

Read More

Configuring a lightweight Apache / MySQL install on Debian/Ubuntu

Posted by cJ | Posted in Debian, Linux, Server, Ubuntu | Posted on 05-10-2008

12

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:

$top

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:

$sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.orig

Now open my.cnf using your preferred editor. We will use nano for this tutorial.

$sudo nano /etc/mysql/my.cnf

Find the following line in your my.cnf file:

#skip-innodb

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:

skip-external-locking

and add:

skip-locking

below it. Next find the section labeled Fine Tuning. Change the settings in that section to match:

key_buffer = 16K
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:

$sudo /etc/init.d/mysql restart

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.

$sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.orig

Now lets open the apache config file for editing:

$sudo nano /etc/apache2/apache2.conf

Now make your entries match the following:

Timeout 45
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 3
<IfModule mpm_prefork_module>
StartServers          5
MinSpareServers       5
MaxSpareServers      10
MaxClients          30
MaxRequestsPerChild   2000
</IfModule>

Finally restart apache:

$sudo /etc/init.d/apache2 restart

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.

Comments (12)

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.

Write a comment