Tuning Apache/Mysql for a low memory footprint

Contents

Apache
Mysql

Apache

Here is a quick tip on how to tune Apache for a low memory foot print.
The Apache conf file is located in your /etc/httpd/conf directory.
First type the following:

cd /etc/httpd/conf
cat httpd.conf|less

I recommend reading the whole file as it has some good information in it.
Look for the section that says the following:

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000

Here is one way to change the conf file to reduce the memory foot print.
Using vi make the file look like this:

StartServers 1
MinSpareServers 1
MaxSpareServers 5
ServerLimit 64
MaxClients 64
MaxRequestsPerChild 400

As this is just one suggestion I recommend that you continue to tweak your
settings till you find one that works for you.

Mysql

Here is a quick Tip on tuning your Mysql for a low memory footprint.
First type the following: cat /etc/my.cnf You will see something like this:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
skip-bdb

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Below is an example of what to put in /etc/my.cnf using a editor like vi:

[mysqld]
port = 3306
socket = /var/lib/mysql.sock
skip-locking
set-variable = key_buffer=16K
set-variable = max_allowed_packet=1M
set-variable = thread_stack=64K
set-variable = table_cache=4
set-variable = sort_buffer=64K
set-variable = net_buffer_length=2K

#NOTE: If you do not use innoDB tables, remove support for the program by
#adding this line to /etc/my.cnf:
skip-innodb

Here is a sample my.cnf file from Quantact for use on our VM's.
NOTE: make backup copy of your current my.cnf before you get the sample.
Type the following:
wget http://www.quantact.com/dl/my.cnf