Ubuntu Minimal, Lighttpd, Perl CGI, PHP and & MySQL with Tiny Memory

The following setup is designed to provide a webserver with Perl, PHP and MySQL database, for Linux Ubuntu Server, that fits well inside 64MB of RAM. My tests with Ubuntu Dapper LTS Server and Ubuntu Hardy LTS Server show that it consumes less than 40MB of memory and uses up less than 400MB of disk space.

For comparison, doing this with default installs of Apache2 and MySQL5 instead, consumes more than 200MB of memory.

This is ideal for:



First, install Ubuntu Server with minimal options.

Next, just issue the following commands:

sudo su -
apt-get install lighttpd php5-cgi mysql-server-5.0 php5-mysql
lighty-enable-mod cgi

mv /etc/mysql/my.cnf /etc/mysql/my.cnf-orig
cat <<! >/etc/mysql/my.cnf
# Example MySQL config file for tiny systems

# Main MySQL server options
port = 3306
socket = /var/run/mysqld/mysqld.sock

# No locking at all!

# Set internal buffers, caches and stacks very low
key_buffer = 16K
max_allowed_packet = 16K
table_cache = 1
sort_buffer_size = 16K
read_buffer_size = 16K
read_rnd_buffer_size = 1K
net_buffer_length = 1K
thread_stack = 16K

# Don't listen on a TCP/IP port at all.
# Will still work provided all access is done via localhost
server-id = 1

# Skip Berkley and Inno DB types
#skip-bdb # BDB now deprecated 2011-02-04

# Set the query cache low
query_cache_limit = 1048576
query_cache_size = 1048576
query_cache_type = 1

# Set various memory limits very low, disable memory-hogging extras
max_allowed_packet = 16K
key_buffer = 16K
sort_buffer_size = 16K
key_buffer = 16K
sort_buffer_size = 16K

/etc/init.d/mysql restart
/etc/init.d/lighttpd restart
Update 2011-02-04: BDB is now deprecated, have commented out skip-bdb

Public Domain - Andrew Oakley - 2008-03-06

Top - More Computing Articles - Article Index -