aoakley.com

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:

Caveats:

Setup

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
[mysqld]
port = 3306
socket = /var/run/mysqld/mysqld.sock

# No locking at all!
skip-locking

# 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
skip-networking
server-id = 1

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

# 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
[mysqldump]
quick
max_allowed_packet = 16K
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 16K
sort_buffer_size = 16K
[myisamchk]
key_buffer = 16K
sort_buffer_size = 16K
[mysqlhotcopy]
interactive-timeout
!

/etc/init.d/mysql restart
/etc/init.d/lighttpd restart
exit
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 - aoakley.com