Getting version control working on a new install of Expression Engine
Upcoming SlideShare
Loading in...5

Getting version control working on a new install of Expression Engine



The document covers the process of getting version control running on a new install of Expression Engine across a local, development and production. ...

The document covers the process of getting version control running on a new install of Expression Engine across a local, development and production.

It's a rough draft and not meant asa step by step tutorial. If you are stuck or have suggestions fire them at

Good luck.



Total Views
Views on SlideShare
Embed Views



1 Embed 1 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Getting version control working on a new install of Expression Engine Getting version control working on a new install of Expression Engine Document Transcript

  • A WORKING DOCUMENT Getting version control working on a new install of Expression Engine gregor@goldhawklabs.comThe following documents the process I went through to get version control running on a newinstall of Expression Engine across a local, development and production environment.Caveats ● Expression Engine uses the database to store a lot of details about your site. This means more work is needed to have database changes syncing - this is not really covered in this outline. ● There are other ways to set up version control (see bootstrap) - but nonetheless it’s a document I wish I had a while back... ● I’ve tried to keep this as non-technical as possible - and thus have stayed away from the command line ● The outline covers a basic install - the more addons and customisations you have the greater the complexity (particularly when trying to stay close to database changes)The tools you need ● A mac - your machine ● MAMP - your local web server and database ● A Beanstalk account - your repository ● Git Tower - your local version control app ● A license of Expression Expression ● A hosting account ● A text editor ● Patience - getting version control running is worth itTo start with before you do anything else ● Buy a Mac ● Install MAMP ● Buy Git Tower and install on your Mac ● Sign up to Beanstalk ● Buy a license of Expression Engine ● Sign up for a hosting account ● Get a coffee - I estimate that this will take 2 - 3 hours23 small steps for an Expression Engine designer Written by Gregor McKelvie | v0.1 - September 2012
  • Some of these steps are easy, so I haven’t elaborated on them, but if you want moreinformation get in touch1) Login to Beanstalk and create a new Git repository (this will be known as a remoterepository). This repository stores all versions of your code.2) On creating the repository, you’ll be given a prompt to “Open in Git Tower”. Select this option. Written by Gregor McKelvie | v0.1 - September 2012
  • 3) In the “Clone Remote Repository” pop up that appears select “Browse” to select where youwant to run your local version of the repository. This is the local version of your site, so shouldbe within the “htdocs” folder within MAMP e.g: /Applications/MAMP/htdocs/localdev_your-siteNOTE: “locadev_your-site” is your root folder where you will install Expression EngineOpen the local repository in Git Tower and you should see your local branch (called Master)under BRANCHES. --- That’s us done with Git Tower and Beanstalk for just now ---4) Set up your databases and document the usernames, passwords and database details Written by Gregor McKelvie | v0.1 - September 2012
  • For this document we are creating: ● A local environment ● A development environment ● A production / live environmentSo you should have created blank databases within phpMyAdmin and have details like: ● db name: myeedatabase ● db user: myeeuser ● db password: mypassword ● db server: localhostStore these details for each environment in something like Basecamp’s Writeboards or a Wiki5) Download and install Expression Engine on your local machine in the local git repository youcreated (e.g. /Applications/MAMP/htdocs/localdev_your-site)NOTE: I always store the system folder behind the root folder and rename the system folder.Standard setup: ● /Applications/MAMP/htdocs/localdev_your-site/system ● /Applications/MAMP/htdocs/localdev_your-site/themes ● /Applications/MAMP/htdocs/localdev_your-site/index.php ● /Applications/MAMP/htdocs/localdev_your-site/admin.phpMy set-up ● /Applications/MAMP/htdocs/localdev_your-site/your_system ● /Applications/MAMP/htdocs/localdev_your-site/public_html/themes ● /Applications/MAMP/htdocs/localdev_your-site/public_html/index.php ● /Applications/MAMP/htdocs/localdev_your-site/public_html/admin.phpWith the above set-up your system path within index.php and admin.php would read: $system_path = ./../your_system;It’s up to you how you do it6) Once you have installed Expression Engine and can login to the control panel you need toedit the database and config files within: /Applications/MAMP/htdocs/localdev_your-site/expressionengine/config/Do the following in database.phpChange:$db[expressionengine][hostname] = localhost;$db[expressionengine][username] = myeeuser;$db[expressionengine][password] = mypassword;$db[expressionengine][database] = myeedatabase; Written by Gregor McKelvie | v0.1 - September 2012
  • Toif($_SERVER[HTTP_HOST] == "localhost:8888"){ $db[expressionengine][hostname] = localhost; $db[expressionengine][username] = myeeuser; $db[expressionengine][password] = mypassword; $db[expressionengine][database] = myeedatabase;}if($_SERVER[HTTP_HOST] == ""){ $db[expressionengine][hostname] = devhost; $db[expressionengine][username] = devuser; $db[expressionengine][password] = devpassword; $db[expressionengine][database] = devdatabase;}if($_SERVER[HTTP_HOST] == ""){ $db[expressionengine][hostname] = "productionhost"; $db[expressionengine][username] = productionuser; $db[expressionengine][password] = productionpassword; $db[expressionengine][database] = productiondatabase;}And change:$db[expressionengine][cachedir] = /Applications/MAMP/htdocs/localdev_your-website/your_system/expressionengine/cache/db_cache/Toif($_SERVER[HTTP_HOST] == "localhost:8888"){ $db[expressionengine][cachedir] = /Applications/MAMP/htdocs/localdev_your-website/your_system/expressionengine/cache/db_cache/;}if($_SERVER[HTTP_HOST] == ""){ $db[expressionengine][cachedir] = /home/sites/;}if($_SERVER[HTTP_HOST] == ""){ $db[expressionengine][cachedir] = /home/sites/;} Written by Gregor McKelvie | v0.1 - September 2012
  • Do the following in config.phpChange:$config[cp_url] = http://localhost:8888/localdev_your-webiste/public_html/admin.php;To:if($_SERVER[HTTP_HOST] == "localhost:8888"){ $config[cp_url] = http://localhost:8888/localdev_your-website/public_html/admin.php;}if($_SERVER[HTTP_HOST] == ""){ $config[cp_url] =;}if($_SERVER[HTTP_HOST] == ""){ $config[cp_url] =;}And change$config[base_url] = ;Toif($_SERVER[HTTP_HOST] == "localhost:8888"){ $config[base_url] = ;}if($_SERVER[HTTP_HOST] == ""){ $config[base_url] =;}if($_SERVER[HTTP_HOST] == ""){ $config[base_url] =;}NOTE: you might also need to change:$config[uri_protocol] = AUTO;...depending on your server environment (I need AUTO for local and ORIG_PATH_INFO for devand production) Written by Gregor McKelvie | v0.1 - September 2012
  • 7) Add an .htaccess to you public_html folder to suit your hosting environment and if you want toremove the index.php from the URL. Some hosting environments have different requirements,but hopefully you’ll be OK with: RewriteEngine on RewriteCond $1 !.(gif|jpe?g|png)$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]8) If you remove your index.php then login to the Expression Engine control panel on your localenvironment and remove the index.php from “Name of your sites index page” within “GeneralConfiguration”. You’ll need to remove it from the config file too: $config[index_page] = "";This is all standard Expression Engine stuff, so haven’t gone into detail. I also recommend youdo these two things on each environment when up and running as good practice: ● ● Login in to phpMyAdmin within MAMP and export a copy of the database you set-up on yourlocal environment. Save it as an SQL file.This is a clean database and should have no entries, channels, etc. The only table that will haveany of your preferences is “exp_sites”10) Import the database into your development database (probably within phpMyAdminagain depending on your hosting). You’ll need to do the same for production the productionenvironment. --- Now we go back to setting up version control ---11) Open up Git Tower. Your Master branch should have (HEAD) beside it. In the “status” tabyou should see a list of files that have been added to your local environment (your ExpressionEngine instal).Select “Stage All” and then “Commit”. This prepares the files for publishing to the repository.12) Once the files have been committed, drag and drop the “Master” branch on to “origin” andconfirm you want to publish. This will publish your changes in your local environment to therepository. It will take a while, as there is a lot of files.Go and get another coffee13) Now... what you want is the following: ● One branch on your local machine called “dev” ● Two branches in your remote repository called “master” and “dev” respectively Written by Gregor McKelvie | v0.1 - September 2012
  • 14) To achieve this, right hand click on the local “Master” branch and select “Remove tracking”15) Then rename “Master” to “dev”16) Then drag and drop “dev” to “origin” and confirm you want to create a new remote branchcalled “dev”This is where magic starts to happen.NOTE: you should always work on the local “dev” and publish to the remote “dev” for testing.Only once you are sure everything will work should you publish changes to the remote “master”.17) Login to Beanstalk18) Under “Deployments” within “your ee repository” select “Add an environment”. Yourenvironment is your hosting environment, so you should have two (one for dev and one forproduction)19) You set-up the environment by using FTP details. You can check the connection withinBeanstalk. FTP details will be provided by your web host.20) IMPORTANT: for the dev hosting environment: ● Set the “deployment mode” to “automatic“ ● And set the “default branch” to “dev”For the production hosting environment: ● Set the “deployment mode” to “manual“ ● And set the “default branch” to “master” Written by Gregor McKelvie | v0.1 - September 2012
  • It’s important you get this round the right way! It means that when you publish changes fromyour local dev environment they will be pushed automatically to your dev hosting environment.You wouldn’t want that with production...21) Within “deployments” and for the dev environment select “deploy” and do a manual deployto your hosting environment.22) Once this has completed, go to and you should beable to login to the control panel23) Within the Expression Engine control panel go to “General Configuration” and change theURLs and directories for the dev environmentSUGGESTION: I suggest that you save templates to files within template manager (and do thisfor the local environment too). I also suggest you install Snippet Sync, so that you can managesnippets and global variables within a text editor. In the case of Snippet Sync add the addon tothe local environment and the commit and publish it to the dev environment (you will still haveto login to the dev and production control panel and install it (just like all other modules andaddons). --- You have now set up a local environment, a repository and pushed code from the local environment to the dev environment. Set up your production environment by doing a deploy from the master to your production hosting within Beanstalk and following steps 22 and 23. ---LimitationsWhat you now have is a clean installation on local, dev and production environments that youcan push code to. The big problem happens when you start adding channels and modules, asthese affect the database. It is worth persevering and finding out what works for you. You havethree options to handle database differences:1) Manage most of your code from files like savings templates and snippets to files andconfigure Expression Engine channels etc on each environment separately. This is a paininitially, but once the site is up and running you very rarely have significant database changes(it’s more likely to be new addons or template changes). Written by Gregor McKelvie | v0.1 - September 2012
  • 2) Make changes to the dev and production databases by using SQL queries. This is obviouslymuch harder to do - and I’d argue marginally quicker than 1) for a non-techie3) Set up database version control. I have little experience with this, so can’t comment hugely.DBDeploy is a tool used for this.Ultimately, although 1) and 2) involve some extra work - it is nothing compared to not havingversion control up and running. Once you have it in place you’ll wonder how you ever managedwithout it.---This document is a rough draft (and working document). If you have any suggestions or seemistakes then please contact luck. Written by Gregor McKelvie | v0.1 - September 2012