Using git to Manage an ExpressionEngine website : Setting Everything Up
Published on 9th June, 2009 by Stephen Lewis
This is the second in a series of posts about using git to manage an ExpressionEngine website. If you’re new here, you may want to start at the beginning.
The first installment in this series was little more than an introduction. Now it’s time to get your hands dirty, setting up git, and laying the groundwork for your day-to-day development tasks.
Before you get to the nitty-gritty, it’s worth taking a moment to review what exactly you’re working towards.
What you’re working towards
The setup described below is pretty simple, but can be easily expanded to accommodate more developers, or more “staging” servers.
Dealing, as it does, with the ins-and-outs of setting up your development environment, this will be the most implementation-specific article in this series. If you’re using a different operating system, or a different hosting company, you’ll most likely need to adapt a few of the step-by-step instructions accordingly.
At this stage, it’s also worth stating the obvious; that these instructions are presented as-is, without warranty or guarantee. We’re all grown-up boys and girls, and whilst these instructions worked (and continue to work) just fine for me, if you accidentally delete the internet whilst following them, it’s not my fault.
Caveats dispensed with, here’s what you’ll be setting up:
- The local development environment is where all of the work gets done on a day-to-day basis. Each developer has his own local git repository, enabling him to commit changes into source control quickly and easily, even when he’s offline. He can then periodically
pushwhatever local changes he’s made to the “origin” repository.
- The “origin” repository lives on a remote (DreamHost) server. Every other git repository pushes and pulls to and from this repository.
- The live site (and / or staging site) is another git repository, living on a MediaTemple (dv) server. Updating the live site is simply a case of SSHing into the server, and pulling the latest code from the origin repository. A more seamless alternative would be to use Capistrano.
Laying the foundations
Before you can start pushing and pulling your code about the place, you need to get everything set up.
Step 1. Install git on your local development machine
If you’re feeling particularly adventurous, there’s always the option to compile and install git manually, but unless you have very specific requirements, it’s probably not worth the effort.
Windows users may find this useful.
Step 2. Install git on DreamHost
In a piece of tremendous good fortune, it appears that DH now installs git as standard on new hosting accounts. To confirm that you’re all set up and ready to go, SSH into your DH account, and run the following commands:
[server]$ which git
[server]$ git --version
git version 126.96.36.199
If you’re one of the unlucky few not to have git installed, the official DreamHost Wiki has detailed instructions for installing git.
Step 3. Install git on MediaTemple
After the effortless ease with which you glided through steps 1 and 2, you may be thinking now is a good time to kick back with a self-congratulatory cup of tea.
Not so fast.
Installing git on a MediaTemple (dv) server actually requires a (little) bit of effort, and whilst the MT knowledgebase article is a good starter for 10, it doesn’t work quite as advertised.
MediaTemple recommends using Yum to manage the installation of software on your (dv) server, but unfortunately the knowledgebase guide to installing Yum falls a bit short, neglecting to mention a number of Yum’s dependencies.
This leads to lots of errors message, typically followed by loud and sustained cursing. Not to worry, you can benefit from my bitter experience by following the Yum installation instructions below:
- Install the developer tools via your AccountCenter.
- Log into your (dv) server using SSH:
- Install Yum’s dependency files:
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/yum-metadata-parser-1.1.2-2.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/python-elementtree-1.2.6-5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/python-sqlite-1.1.7-1.2.1.i386.rpm
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/rpm-python-4.4.2-48.el5.i386.rpm
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/m2crypto-0.16-6.el5.2.i386.rpm
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/python-urlgrabber-3.1.0-2.noarch.rpm
- Install Yum:
rpm -Uvh http://mirror.centos.org/centos/5.2/os/i386/CentOS/yum-3.2.8-9.el5.centos.1.noarch.rpm
Once that’s done, you can return to MT’s standard git installation instructions:
- Install EPEL:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm
- And finally, install git:
yum install git
Making life easy for yourself
At this point, you should have everything setup and ready to go. If you’ve had enough for one day, feel free to go and have that cup of tea now.
If you’re still bursting with Terminal energy, there are a couple of additional things you can do that will make your life at the command line at lot simpler.
As you’re going to be doing a lot of SSHing between servers, it’s worth spending a few minutes setting up some SSH keys. Otherwise you’ll spend your life mistyping passwords in the Terminal.
Here’s how to setup an SSH key on your local development machine. Do this for each remote server that you want to access via SSH (DreamHost and MediaTemple, in this setup).
- Open the Terminal. At the prompt, type:
- Specify the file as
key_nameis the name you wish to assign to this SSH key.
- Enter a passphrase.
- Copy the public key to your remote server:
scp ~/.ssh/key_name.pub email@example.com:./key_name.pub
- Secure shell into the remote server using
ssh firstname.lastname@example.org. You’ll still need to enter your password at this point.
- At the prompt, type
ls -l, to list all the files and directories in the current folder. If the
.sshdirectory already exists,
cd .sshinto it, and skip to step 12.
- Create the
- Change the directory properties:
chmod 700 .ssh
- Move to the
- Create a new file:
- Change the file permissions:
chmod 600 authorized_keys
- Add your public SSH key to the “authorized keys” file:
cat ../key_name.pub >> authorized_keys
- Remove your public SSH key file:
- Exit the remote server:
- On your local machine enter:
With that out the way, you can now log into your DreamHost or MediaTemple server using
ssh email@example.com, without entering a password.
It’s also worth taking the time to set up an SSH key on MediaTemple, so you can easily log into your DreamHost server from your MediaTemple server. Here’s how to do that:
- Log into your MediaTemple server as root:
- Follow the instructions above, substituting the file path in step 3 with:
- Add the code from this MediaTemple knowledgebase article to your
Even easier SSH
You can shave even more keystrokes off your day by adding SSH “aliases” to your
config file. You can then log into your remote server by typing (for example)
ssh dh, instead of the much less catchy
To achieve this state of keyboard Zen, add the following block of code to your
~/.ssh/config file, for each server you’re connecting to.
# You probably won't need to specify the port, so just omit the following line
After a suitable recovery period, the next installment will deal with the task of setting up your ExpressionEngine site as a git repository. In the meantime, please join the discussion.
In this section
- Iconic Interiors Shortlisted for “Top 10 Sites of 2008” Interactive Media Award
- Using git to Manage an ExpressionEngine website : Setting Everything Up
- Using git to Manage an ExpressionEngine website : Starting the Conversation
- Labgruppen.com Bags an “Outstanding Achievement” Interactive Media Award
- The Lack of Enterprise Show