Let's continue with the second part of the series with the goal of setting up a virtual server for developing and testing our hwdMediaShare site in an easy, fast and reproducible way.

We'll start by introducing the tools that will make that possible:

VirtualBox

VirtualBox is virtualization software available on all major operating systems. Unlike other enterprise solutions like VMWare or Xen, VirtualBox is far easier to setup and manage. Within our workstation (host) we can create multiple virtual machines (guests), which may even have different operating systems than the host (in our case we'll use an Ubuntu 14.04 guest).

Vagrant

Vagrant is a tool that greatly helps with the management and configuration of virtual development machines, to the point that with a single command it will create the server for us (whether local or on our favorite cloud provider), and will run the scripts to configure it to our needs. That saves a good amount of work when compared with the steps required to create a VM manually.

Some of the features that make Vagrant such an useful tool are:

  • Despite of being a command line tool, it is extremely easy to use, and for our day to day work we'll just need to use 3 commands.
  • Supports the most popular virtualization managers (VirtualBox, VMWare, Hyper-V) and cloud 'infrastructure as a service' providers such as AWS, Rackspace, Digital Ocean and more through its plugins.
  • Can automate the customization of the VM using a range of configuration management solutions, like bash scripts, Chef, Puppet, Salt, Ansible.
  • Shares local folders with the test server. This is very useful as we can keep using our favorite IDE on our workstation, while applying the updates immediately on the server.

Chef

Chef is an Open Source configuration management tool. Through a series of recipes and cookbooks it creates the different resources to configure our server, like packages, folder, configuration files, databases, services, etc.

Git

(Optional) Git is the most popular Source Control Management solution. Even when it's not required to complete our example, I strongly recommend you to use it a part of your development workflow. If you don't like git there are some options available, like Mercurial, Bazaar or good old SVN. Most modern IDEs have plugins to make Git management easier.

Getting our hands dirty

  1. Download and install the last version of VirtualBox for your o.s. from https://www.virtualbox.org/wiki/Downloads
  2. Download and install Vagrant from https://www.vagrantup.com/downloads.html
  3. Install the vagrant-omnibus plugin to automatically install Chef on your VMs. To do so open a terminal window (cmd.exe on Windows, iTerm on MacOSX) and run vagrant plugin install vagrant-omnibus
  4. (Optional) Download and install GIT from http://git-scm.com/downloads (or homebrew on MacOSX, or the repos of your favorite Linux distro)
  5. Clone the following repo from github: https://github.com/marpada/vagrant-hwdmediashare. You can also download the ZIP file https://github.com/marpada/vagrant-hwdmediashare/archive/master.zip and uncompress it on your workstation.
  6. Edit the file Vagrantfile on the repo from the previous step. Feel free to adjust some of the parameters at the bottom of the file, like the db credentials to use for Joomla, or the URL of the Joomla package.
  7. On the repository folder, open a terminal window and run: vagrant up

The first time vagrant will download the base Ubuntu 14.04 image (around 500Mb), which might take a while depending on the speed of your connection. After that the actual configuration of the VM will start.

If everything goes ok, you can open a new browser window and go to http://172.28.128.3 and the familiar Joomla installation page will show up. Go ahead with the installation and on the database setup just the credentials on the Vagrantfile (by default host:127.0.0.1 database:joomla user:joomla password:ChangeMe).

First steps

The joomla folder on our project is syncronized with the VM, that is, you can edit the files there using your favourite editor, and the modifications will the updated instantly on the VM. If you clone the repo using git, you can keep track of any changes on the folder. Just remember to commit your changes everything you finish a feature or fix a bug. You can as well copy the content of your production site there so you don't have to start from scratch. Likewise, the logs folder maps the Apache log folder on the server.

MySQL management

To make MySQL management easy adminer, a lightweight alternative to PHPMyAdmin, is included. It can be accessed on http://172.28.128.3/adminer/. You can use it to import a dump from your live database, or export the DB from your test server when it's good to go live.

Media conversion tools

The following tools are included for multimedia conversion:

  • /usr/local/bin/ffmpeg
  • /usr/local/bin/yamdi
  • /usr/local/bin/qt-faststart
  • /usr/bin/convert (Imagemagick)

Suspend the VM

When you are done working with the VM for a while, you can suspend it to save resources with

vagrant suspend

or

vagrant destroy

to delete it for good. You can restore it anytime with

vagrant up

References

If you want to learn more about the tools we've discussed, or just need some visual aid to make sense of them, the following links are a good start:

Conclusion

I hope you find this short series of articles useful in order to easily setup for hwdMediaShare testing environment.

If you have any suggestion about this or following articles about server administration we'll be glad to hear your thoughts on the comments.