Gallery3:Using Vagrant - Gallery Codex
Personal tools

Gallery3:Using Vagrant

From Gallery Codex

The Gallery 3 development environment can easily be set up using Vagrant. Vagrant will download a prebuilt virtual development box configured so you can start hacking almost instantly.

First-time setup

These instructions have been tested on Linux, but the basic process is the same for both Windows and Mac.

Preparing your workstation

Please install the following software:

Recommended versions are in parentheses. That's it! You don't need to have PHP, Apache or MySQL installed on your computer.

Getting the Gallery source code

Fork the repository on GitHub and clone it:

$ git clone git://github.com/gallery/gallery3.git
$ cd gallery3

Don't forget to replace gallery with your own GitHub username.

Copying the Vagrantfile

Vagrant needs to know where to find the Gallery development box. It finds this out by reading a file called `Vagrantfile` in the project root directory. You can obtain this file from here. Executing this command after cloning the repository in the previous step will make sure you have it in the right place:

$ wget https://raw.github.com/jozefs/gallery3-cookbook/master/dist/Vagrantfile

Importing the developer box

The developer box is currently hosted on Google Drive from where Vagrant cannot directly download. So you'll need to download (~550MB) the box manually and import it into Vagrant:

$ vagrant box add gallery3dev /path/to/downloaded.box

Adding a hosts file entry

Add the following entry to your hosts file.

192.168.33.30 gallery3.local

On Linux, you can use this to add the entry:

$ sudo sh -c 'echo "192.168.33.30\tgallery3.local" >> /etc/hosts'

Starting the development box

Everything is ready now for starting the development server! Simply 'up' the box:

$ vagrant up

After Vagrant downloads the box and boots it, you can proceed to your Gallery on the following URL:

http://gallery3.local

Finishing for the day

When you want to take a break from coding, use the following command to stop the box:

$ vagrant halt

Don't worry, if you forget to do this, the box will automatically be shut down when you shut down or restart your computer.

Further reading

If you haven't used Vagrant before, we recommend reading their Getting Started guide to get a better understanding of how it works.

Development box specs

  • Debian 6
  • Apache 2.2
  • MySQL 5.1
  • PHP 5.3.3

By default, it's configured to use a maximum of 1GB RAM.

Cookbook

Executing commands on the development box

To execute commands on the development box, e.g. to run unit tests, you need to log via ssh. In the root of the Gallery source directory, do this:

$ vagrant ssh

You're now logged into the VM. The source code is mounted in /gallery3:

$ cd /gallery3
$ ls

You should now see the Gallery source code. When you're done, you can get back to your host machine:

$ exit

Connecting to the database

MySQL is set up to allow remote connections for the root user. This is to make connecting to the database simpler to developers, and is not suitable for a production environment!

From the host machine:

$ mysql -h gallery3.local -u root -p gallery3

Within the VM:

$ vagrant ssh
$ mysql -h localhost -u root -p gallery3

In both cases there is no password set.

Running the unit tests

Run the unit tests from within the development box:

$ vagrant ssh
$ cd /gallery3
$ php index.php test

Destroying the development box and starting over

If for any reason you'd like to make a fresh start where the development environment is reset and Gallery uninstalled, follow these steps:

$ vagrant destroy
$ rm -rf var
$ vagrant up

Now you'll need to proceed to installing Gallery again:

http://gallery3.local