Mac OSX Ubuntu 12 lts VirtualBox with DropBox DocumentRoot

I’ve just switched from MAMP to VirtualBox for local development. I found Railo was clashing with Apache too much, so I’m going to run 2 different VMs for Coldfusion and PHP development separately.

Installing VirtualBox is easy enough, and creating a Ubuntu VDI (Virtual Disk Image) is easy enough following the wizard.

I downloaded the Ubuntu 12.04 LTS .iso from the Ubuntu website, then mounted that (all pretty easy stuff with VirtualBox) and booted the VM.

This launched the Ubuntu installer, again easy wizard you just run through – at the point where you choose additional software though, I picked LAMP, SAMBA and OpenSSH.

This installs Apache, PHP and MySQL, as well as the SAMBA file sharing server and an OpenSSH server.

When the installer has finished, you need to stop the virtual machine, go into the settings and under “Network” select “Bridged adapter”, this makes sure the VirtualBox gets an IP on your network so you can visit the dev IP and set up your local hosts file to see your dev servers.

So if your new VirtuaBox IP is, on your MAC you’ll need to do this:

sudo vi /etc/hosts
# add this line: localtestserver

Then the awkward part started… I needed to install “Guest Additions”. I don’t really know what this stuff does but I know you need it to get file sharing working.

Under the “Devices” menu from the VirtualBox that’s running, you need to select “Install Guest Additions…”. This mounts an .iso, but I couldn’t find it anywhere in my VirtualBox. Turns out I needed to manually mount the image. Once it was mounted, I could then install the guest additions:

sudo mount /dev/sr0 /media
cd /media
sudo ./

And that installed my Guest Additions! Whatever they are…?

Next, under the settings for the VirtualBox, in the Shared Folders section you can pick a folder on your actual host hard drive (including a folder from DropBox!), and give that a name that Ubuntu system will see. Choose “Auto-mount” to make sure Ubuntu mounts it on startup.

If you restart your VM you should see in the /media/ directory, a new directory that matches the name you chose in the previous step. The problem now, is this is owned by root, belongs to the folder vboxsf and has the permissions 700

pete@wm-lamp/media$ ls -la
total 12
drwxr-xr-x 4 root root 4096 Sep 28 08:30 .
drwxr-xr-x 23 root root 4096 Sep 27 20:31 ..
drwxr-xr-x 2 root root 4096 Sep 27 20:30 cdrom
drwxrwx--- 1 4 root vboxsf 646 Sep 22 10:22 my_new_share

This means I can’t actually use the folder without being root, which is fairly useless. To solve this, I needed to add “pete” and also “www-data” (the user apache runs as) to the group vboxsf. Then there was one more thing to do to get access to that folder… reboot the machine.

Infact, if any of these steps don’t work, reboot the machine between steps… always try turning it off and on again!

One more thing to do then – I wanted to make this new share (which is fixed to the /media directory) my site root.

First you need to make a symlink from your site root to the share:

cd /var/www/vhosts/my_new_site
ln -s /media/my_new_share public_html

You need to make sure that the folders are accessible by www-data, I generally set everything under the vhosts folder to be owned by user, and in the group www-data.

Then create a new apache vhost file to use that share. You need to make sure you set the vhost to follow symlinks – :

cd /etc/apache2/sites-available
sudo cp default my_new_site
sudo vi my_new_site
# set up site root - mine is pointing to /var/www/vhosts/my_new_site/public_html
# make sure ServerName is set to your localtestserver
sudo a2ensite my_new_site
sudo service apache2 reload

Then if you open a web browser and visit http://localtestserver and you will hopefully see your sites in your DropBox folder being served via your Ubuntu virtual machine! Mega convoluted goodness.

I switched to this becuase I like Ubuntu, I use it on lots of other dev servers, it’s a lot more similar to RedHat which I use in production, it’s better than MAMP and I don’t like trying to mix my dev machine with my dev server. It feels tidier once it’s all setup.

And like I said before I can have multiple dev machines and switch between them. At this point I’ll make a clone of the server and keep that as a fresh install so I don’t have to go through this whole process again later.

One more thing, this entry has been a bit scatty, I’ve written it as I’ve gone along so if it’s rubbish let me know and I’ll change it. I’ll probably add some pictures later on in life, but not until I need to use this for reference myself.

Anyway, now I’ve got a decent dev server, I need to go and do some devving.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s