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