Configuring a lightweight Apache / MySQL install on Debian/Ubuntu

5 October 200820,376 views29 Comments

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:

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.

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!

[…] 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.

# 30 January 2009 at 8:37 am

MINEG said:

Hello! Chris could u tell me hwo i can set up a web mail? pls help me. Thank you.

# 6 February 2009 at 5:15 am

cJ (author) said:

I have never setup web mail, or any sort of eMail for that matter, but it may be something for a future article.

# 7 February 2009 at 9:36 am

m3nt0r said:

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.

[…] 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. […]

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?

[…] 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.

“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.

# 27 July 2011 at 8:34 am

SAM said:

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?