Debian Live CD with a LAMP webserver

Description

A live CD is a great way to allow people to learn about interactive websites of the sort built using [http://drupal.org/ Drupal], [http://www.joomla.org/ Joomla!], etc. This guide explains how to build a Debian Live CD using LAMP (Linux, Apache, MySQL and PHP). The process has been tested for Drupal using Lenny (Testing).

Outline

Initial build

Create the build environment on the host

{{{$ cd $ mkdir live $ cd live $ lh_config }}}

Packages list

To save time, use the base system initially and add the extra essential packages using this packages list:

{{{# local-pkg-lamp # packages list for live-helper(7) with basic LAMP

# You need the local packages if you want to set a # different locale/keyboard map locales

# Apache2 apache2 php5 libapache2-mod-php5 php5-mysql

# mysql mysql-server mysql-client mysql-common

# php php5 libapache2-mod-php5 php5-mysql

# console browser for testing lynx

# ssh and scp for networking between host and guest openssh-client openssh-server }}}

Put the package list file local-pkg-lamp in config/chroot_local-packageslists.

{{{config/chroot_local-packageslists/local-pkg-lamp }}}

Test files

Create this Apache/PHP test file (phpinfo.php):

{{{<?php phpinfo (); ?> }}}

Put phpinfo.php into config/chroot_local-includes/var/www, creating directories as necessary.

{{{config/chroot_local-includes/var/www/phpinfo.php }}}

Put the MySQL export file (eg mydb.sql) into config/chroot_local-includes/etc

{{{config/chroot_local-includes/etc/mydb.sql }}}

Build the image

Configure the use of the packages list with --packages-lists local-pkg-lamp and, optionly, your locale with --bootappend-live "locale=en_GB.UTF-8 keyb=uk" (for the UK). Build the image (takes some time).

{{{$ lh_config \

# lh_build }}}

The image will eventually be built - binary.iso.

Test the image

Set up VirtualBox to test the image as discussed in ["DebianLive/Virtualbox"]. In addition set up networking between the host and the virtual guest to enable copying of files between the two using scp. Do this as follows.

Set up a network bridge as described at http://samiux.wordpress.com/2007/07/11/bridge-network-interface-on-virtualbox/. This shell script, run as root, does the job.

{{{#!/bin/sh # networking.sh # Set up networking in Virtualbox. Run as root

# Load the VirtualBox driver module into the kernel. modprobe vboxdrv

# Create TAP interface - tunctl -t tap1 -u chris

# where “chris” is the username in the host

# Create a br0 bridge - brctl addbr br0

# Make your real network interface be promiscuous - ifconfig eth0 0.0.0.0 promisc

# Link your real network interface to bridge br0 - brctl addif br0 eth0

# Assign an IP to the br0. If you are using DHCP - dhclient br0

#Or, if you assign an IP yourself - # ifconfig br0 192.168.1.102 # the IP may be different from yours.

# Link TAP to bridge br0 - brctl addif br0 tap1

# Activate TAP interface - ifconfig tap1 up

# Change the permission of /dev/net/tun - chmod 0666 /dev/net/tun

# At the VirtualBox startup panel, choose “Host Interface” and add “tap1″ to “Interface Name”. }}}

For alternative methods of doing this, see also For alternative methods see also http://wiki.debian.org/VirtualBox file:///usr/share/doc/virtualbox-ose/README.Debian.html

Run binary.iso on the virtual machine.

In order to use scp, you need to know the IP address of the host and the guest. The guest at least gets its IP from DHCP, perhaps the host too. An easy way to discover the local IP is to ping a non-existent IP on the network. The local IP appears on the line telling you that the remote IP is unreachable. Do this for the host and the guest once they guest is running in VirtualBox.

{{{2$ ping 192.168.1.44 PING 192.168.1.44 (192.168.1.44) 56(84) bytes of data. From 192.168.1.20 icmp_seq=1 Destination Host Unreachable }}}

There is probably a more elegant way of doing this.

Check that Apache works

Go to the URL "localhost" using the console browser Lynx in the guest. If you see "It works!", then it works.

{{{$ lynx localhost It works! q Are you sure you want to quit? y }}}

Check that PHP works

Go to the URL "localhost/phpinfo.php" using the console browser Lynx in the guest. If you see the PHP version number and lots of other information, then everything is OK.

{{{$ lynx localhost/phpinfo.php PHP Logo PHP Version n.n.n.n ... q Are you sure you want to quit? y }}}

Check that MySQL works

Manually set up a password for root. (This will be lost on reboot.)

mysqladmin -u root password new-password

Create the database "mydb" and import data from the mydb.sql file.

{{{$ mysqladmin -u root -pnew-password create mydb $ mysql -u root -pnew-password mydb < mydb.sql }}}

Check the database. {{{$ mysql -u root -pnew-password > show databases > quit }}}

These commands will later be put in an init file which will run during boot.

Shut down the guest in VirtualBox.

{{{Machine -> Close Power off the machine -> OK }}}