“Less is more” – I want to install only the absolutely necessary programs on my new MacBook Air. I believe keeping things simple is more productive. As a web developer I create a lot of projects in my web directory. I do projects for customers, some as a sourced resource, and then projects for my self. This article by Dan Adams inspired me to setup a local web server using Ubuntu on VirtualBox sparing my MBA from cluttering up – and leaving my DropBox directory as an easily sharable holder for web projects.
Download VirtualBox here and the Ubuntu LTS server here.
VirtualBox configuration
Create a Host-only bridge network and attach as adaptor 2 on the Virtual machine:
Virtualbox Preferences
Select “Network” tab
click the small “add host only network” icon
insert IPv4 address: 192.168.56.1
insert IPv4 Network mask: 255.255.255.0
At the DHCP tab, UNTICK the “enable server”
Create new Virtual Machine
On the “Network” tab, Enable Adapter 2
Select “Host only adapter”
The Adaptor name should be auto-populated with “vboxnet01”.
On the “Storage” tab, select the Ubuntu iso to be mounted in the cd-rom.
I selected 1 GB memory for this server – should be enough for OS, database, web server and APC.
Start the virtual machine, and begin Ubuntu installation.
Installing Ubuntu
Select installation language
Select to install
Select locale (language) for installed system
Select primary network eth0 (eth1 is the bridged-host, we configure this later)
Choose a hostname for your server (here we use “testhost”)
enter your full name
enter login name
enter a password x 2
select no to encrypt your home directory (you are not really going to use it)
verify the time zone
choose “guided – entire disk”
select the disk that are presented
verify the disk selection
You do not need a external http proxy
Select Install security updates automatically
Select OpenSSH server and LAMP Server
Enter a password for root/MySQL user
accept GRUB boot loader on the drive
installation is complete (press continue)
Configure the server
login using your login name and password
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install dkms build-essential linux-headers-generic module-assistant
sudo m-a prepare
sudo apt-get install uml-utilities bridge-utils
sudo modprobe tun
sudo apt-get install xserver-xorg xserver-xorg-core
sudo apt-get install virtualbox-ose-guest-x11
Installing the VirtualBox Guest Addon
This will allow sharing files between your host (mac osx) and the guest (ubuntu).
For virtualbox reference / how to setup reference.
Now on the VirtualBox window, select the icon for the cd, if the ubuntu iso is mounted, remove it. Then via the VirtualBox administration menu, select “devices -> install guest addons” – this only mounts the guest addon iso in the virtual cd-rom (it does not install it!).
In the terminal logged into the guest, enter the command
sudo mount /dev/cdrom /media/cdrom
cd /mount/cdrom
sudo sh ./VBoxLinuxAdditions.run
yes continue to overwrite some other installation (the virtualbox-ose-guest-x11)
Configure network
(using this as a reference: http://christophermaier.name/blog/2010/09/01/host-only-networking-with-virtualbox)
sudo vi /etc/hosts
insert 192.168.56.102 testhost (or whatever your hostname is)
sudo ifconfig eth1 192.168.56.102 netmask 255.255.255.0 up
sudo vi /etc/network/interfaces
insert below the others
# my testhost interface
auto eth1
iface eth1 inet static
address 192.168.56.102
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
You also need to make sure the eth1 interface is started automatically when server restarts:
sudo vi /etc/init.d/rc
insert this at last line but ABOVE the “exit 0” line! (press G to go to last line)
ifup eth1
In your Mac terminal (the host system also needs to know the IP-address)
sudo vi /etc/hosts
and insert
192.168.56.102 testhost
Use MAC Terminal to administer your server
Now you can connect to your server via SSH, so open your mac terminal and enter
ssh testhost
accept the RSA key
enter your username and password
Now you can use copy paste which makes administration a little easier.
Removing MySQL
We do not want to use MySQL so we remove it and install MariaDB instead – its a complete substitution and everything will be working as expected, just faster :)
dpkg –get-selections | grep mysql
Remove all of the packages listed by the above command, it will most likely look like this:
sudo apt-get remove libdbd-mysql-perl libmysqlclient18 mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 php5-mysql
Verify they are all removed, if not – repeat the action on the packages with the “purge” command instead:
dpkg –get-selections | grep mysql
sudo apt-get purge package-name-a package-name-b
If asked, KEEP the mysql databases – do not delete them (you do not have any data right now, but if you did this on a system that had been running for a while you could destroy your work…)
Installing MariaDB, phpMyAdmin and APC
You have to do a few manual steps to enable downloading MariaDB
Visit mariadb/repositories and select ubuntu, precise (ubuntu version 12), 5.5 (mariaDB version, latest)
sudo vi /etc/apt/sources.list.d/mariadb.list
insert the text
# MariaDB repository list – created 2012-07-16 15:10 UTC
# http://downloads.mariadb.org/mariadb/repositories/
deb http://mirror3.layerjet.com/mariadb/repo/5.5/ubuntu precise main
deb-src http://mirror3.layerjet.com/mariadb/repo/5.5/ubuntu precise main
And then get the pgp key from http://kb.askmonty.org/en/installing-mariadb-deb-files/
sudo apt-key adv –recv-keys –keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo apt-get update
sudo apt-get install mariadb-server
enter password for mariadb root x 2
Verify installed packages
dpkg –get-selections | grep maria
Install phpmyadmin
sudo apt-get install phpmyadmin
sudo vi /etc/apache2/conf.d/fqdn
insert
ServerName localhost
Install APC
sudo apt-get install php-apc
sudo /etc/init.d/apache2 restart
Mounting your Host web directory on your Guest web directory
While switching my development computer from a PC to MAC, I moved lots of files to my Dropbox account. While my files are moved to this location, I figure the Dropbox account / local directory can host my files instead of duplicating them to a web directory. (I also backup to TimeMachine, in case something weird happens to the Dropbox account).
Get the ID of your apache2 user/group (its most likely 33 for both)
id www-data
Then mount the web filesystem from your host system on a directory created for the occasion on the guest os (the ubuntu server)
sudo mkdir /mnt/www
sudo mount -t vboxsf -o uid=33,gid=33 web /mnt/www
We want to make sure the filesystem is mounted automatically on system restart
sudo vi /etc/init.d/rc
Insert at the line below “ifup eth1” (and ABOVE the “exit 0” line)
mount -t vboxsf -o uid=33,gid=33 web /mnt/www
The apache2 server defaults to look for websites in /var/www
We want to use the mounted /mnt/www files, this is how:
sudo rm -r /var/www
sudo rmdir /var/www
now link the mounted directory to the apache http directory
sudo ln -s /mnt/www /var/www
sudo /etc/init.d/apache2 restart
Now you can edit your MAC files in the shared directory, and use the Ubuntu web-server to configure and serve websites and host the databases.