This article explains my process of setting up a desktop (or development server) for the purpose of web development. The goal is to create a script which reduces downtime when rebuilding a system from scratch.

In this article I will use Ubuntu Linux for my Operating System.

What You will Need

  • Ubuntu Install CD
  • Computer or Virtual Machine to install the software
  • A place to hold your script and associated files. (SFTP server, USB Drive)

You can download the latest Ubuntu release from their website. I recommend downloading the torrent. Alternatively if you just want a development server, you could rent a service from Slicehost or Amazon AWS, they will already have an install of Ubuntu, ready for you to run your script.

Installing Ubuntu

Okay now is the time to install your version of Ubuntu. If you need any help installing Ubuntu there is endless documentation online. If you are installing to a Virtual Machine(VM), you will want to install any tools the VM may require (example: "vmware tools" for VMware).

Getting your files

The first thing I do after a clean install is run my script. My Ubuntu install script installs all of the tools I use on a regular basis. Using this method keeps your Ubuntu install clean so you can move servers very quickly if needed.

We need to get our scripts from where we saved them to our new machine. If you are building a development machine you will probably tar or zip the files and download them using scp.

scp username@servername:/home/username/place_files_are_stored

My Install Script for Ubuntu

I've commented my script as best I can, if you have tips, I'd love to hear them. Also you will notice I've added a private_vars file so I can keep this script up-to-date and still use it myself without giving you any private data.

#!/bin/bash
# Install script for a clean install of Ubuntu 9.04
# v2.0
# Last Updated: Jul 20, 2009
# Documentation: 
# http://www.nickyeoman.com/blog/system-administration/17-project-directory-setup

#check to ensure root
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

#check private vars exists
if [ ! -e private_vars.bash ]; then
	more <<EOT 
You do not have a private_vars.bash file
here is an example file, please modify it
and save it in the same dir
**************************
#Anything that shouldn't be posted on the web goes here.

#Your fastest repository
my_repo=mirror.csclub.uwaterloo.ca

#Home directory
my_home=/home/username/
my_user=username:usergroup

#Install type desktop or server
my_type=desktop
EOT
exit 2
fi

#get private_variables
. private_vars.bash

#####################################
#	APT SECTION
#####################################
#Set repositories for fastest install
#must have default server (archive.ubuntu.com) to work!
if [ "$my_type" = "desktop" ]; then
	sed -i.bak2 "s/archive.ubuntu.com/$my_repo/g" /etc/apt/sources.list
fi

# Update
apt-get -y update

# Install Lamp and ssh
apt-get -y install lamp-server^ 
apt-get -y install php5-imagick php5-gd 

# Install Open SSH
apt-get -y install openssh-server openssh-client

# Server tools
apt-get -y install subversion php5-cli nmap

# My Personal Preferences for a desktop install
if [ "$my_type" = "desktop" ]; then
	apt-get -y install scite mysql-query-browser phpmyadmin
	apt-get -y install k3b amarok krename vlc picard ktorrent thunderbird
fi

#Clean things up
apt-get -y upgrade
apt-get autoclean
apt-get clean

#####################################
#	Remove junk
#	And setup home dir
#####################################
#TODO: I think it would be best to build the user from scratch 
#      instead of cleaning up Ubuntu's crap
if [ "$my_type" = "desktop" ]; then
	rm -rf /usr/share/example-content/*

	#I can setup my own home dir thank you
	cd $my_home
	rm -rf Documents Music Pictures Public Templates Videos examples.desktop
	mkdir Downloads tmp
	chown $my_user *
fi

#####################################
#	Apache SECTION
#####################################
# Apache was installed in the APT section

#enable mod-rewrite
a2enmod rewrite && /etc/init.d/apache2 restart

# This is unique to your webhost
if [ "$my_type" = "desktop" ]; then
	#Impersonate MediaTemple's internal mysql connection
	echo "\n 127.0.0.1 $internaldb" << /etc/hosts
fi


#ALL DONE
#TODO: SSH Keys ( Maybe put them in my vars then cat them)
#TODO: Grab subversion dirs (might not want this if it will be svn repo)
#TODO: Setup Apache to reflect svn dirs (this would be good)

You will want to update this script to suit your personal needs. You might want a different text editor or may not need GD, up to you, edit as you see fit.

Comments

Show/Hide Comment form