$30 off During Our Annual Pro Sale. View Details »

Environments and Version Control in EE - The Wh...

Erik Reagan
October 22, 2011

Environments and Version Control in EE - The Why and How

These slides are from my presentation at EECI2011. I exploring reasons for using a version control system while building and maintaining ExpressionEngine websites.

We also look at why (and some of the "how") you should use multiple environments in your workflow.

Erik Reagan

October 22, 2011
Tweet

More Decks by Erik Reagan

Other Decks in Programming

Transcript

  1. ERIKREAGAN • EECI 5 35 24 19 6-10 years 3-5

    years Over 10 years SURVEY SUBMISSIONS Web Development Experience
  2. ERIKREAGAN • EECI 6 40 19 12 4 3 3-4

    years SURVEY SUBMISSIONS ExpressionEngine Experience 0-2 years 5-7 years pMachine None
  3. ERIKREAGAN • EECI 7 66 64 38 21 20 19

    HTML/CSS/JS markup SURVEY SUBMISSIONS Weekly Responsibilities EE site planning PHP/MySQL development Add-on development Content management Team leader
  4. ERIKREAGAN • EECI 21 WE USE GIT And so do

    the cool kids Linux jQuery Rails Android
  5. ERIKREAGAN • EECI 21 WE USE GIT And so do

    the cool kids Linux jQuery Rails Android
  6. ERIKREAGAN • EECI OLD WAY 1. Duplicate index.html 2. Test

    changes 3. (Maybe save a backup of the previous version) 4. Save over old version losing previous state 22 Single Developer
  7. ERIKREAGAN • EECI NEW WAY 1. Change and save the

    file contents (Retain history of file for future use) 23 Single Developer
  8. ERIKREAGAN • EECI OLD WAY 1. Bob changes part of

    index.html 2. Suzie changes a different part of index.html 3. Bob and Suzie carefully merge changes together 4. Overwrite old version of index.html 24 Development Team
  9. ERIKREAGAN • EECI NEW WAY 1. Change and save the

    file contents (Retain history of file for future use) 25 Development Team
  10. ERIKREAGAN • EECI KEY CONCEPTS • Track certain files •

    Ignore certain files • Commits (History) • Branches • Remote branches 27
  11. ERIKREAGAN • EECI IGNORED FILES • Operating System files •

    Caches • .htaccess (possibly) • Custom uploads from EE • Dynamic images (captchas etc) 29
  12. ERIKREAGAN • EECI # Lame OS files Thumbs.db .DS_Store #

    EE System cache /system/expressionengine/cache/* # Local dev database file /config/config.local.php # Custom Upload Directories /public_html/uploads/* # Captchas /public_html/images/captchas # Asset minification /public_html/min 30 .gitignore
  13. ERIKREAGAN • EECI 31 TRACKED FILES • EE System directory

    • Add-ons • Template flat files • Images, CSS, Javascript & other assets
  14. ERIKREAGAN • EECI COMMIT TIPS • Commit o en (common

    Git practice) • Write detailed commit messages • Review commit log when returning to a project a er a break of any sort • Review commits of development team members 33
  15. ERIKREAGAN • EECI GOOD COMMIT MESSAGE Updated config file with

    new Minimee cache path directory This allows our cache path to be dynamicly absolute based on the environment out code is in. $config[‘minimee_cache_path’] = $base_path . ‘/min’; 35
  16. ERIKREAGAN • EECI BRANCHING WORKFLOW Do what works best for

    you 37 Just make sure you do it for a reason
  17. ERIKREAGAN • EECI REMOTE BRANCHES • Destination for your repository

    / branch • “Origin” of your repository / branch • Server environment for your site • Other team member’s repository / branch 38
  18. ERIKREAGAN • EECI TOPICAL BRANCHING • master • dev •

    feature/x • upgrade/y • bugfix/z 39
  19. ERIKREAGAN • EECI 40 “It's like not wearing a seatbelt

    in your car because you haven't had an accident yet. Don't be silly, version your work.” Iain Urquhart / @iain
  20. ERIKREAGAN • EECI GIT RESOURCES • Book: Pragmatic Version Control

    Using Git • peepcode.com/products/git • whygitisbetterthanx.com • github.com • More available with the presentation download 41
  21. ERIKREAGAN • EECI COMMON ENVIRONMENTS • Production - the public-facing

    “live” site • Staging - typically used for a final test • Development - shared team development • Local - each developer’s local instance 44
  22. ERIKREAGAN • EECI 52 “Local development is incredibly fast and

    you don't have to worry about setting up crazy conditionals and memeber preferences to hide what you are working on on the live site.”
  23. ERIKREAGAN • EECI 53 “Multiple environments allow us to build

    locally without affecting others and preview new features to clients - without losing the ability to quickly apply updates to the current live site.”
  24. ERIKREAGAN • EECI 54 “Automated deployments and multiple environments are

    essential to any agile-oriented developer. They save time, reduce errors and streamline site maintenance.”
  25. ERIKREAGAN • EECI GETTING SET UP • Server paths •

    URL root • EE upload paths • Debug mode intentions • URI support (PATH_INFO) • Cache settings 56 What’s Unique?
  26. ERIKREAGAN • EECI GETTING SET UP ✓ Server paths ✓

    URL root - EE upload paths ✓ Debug mode intentions ✓ URI support (PATH_INFO) ✓Cache settings 58 What can be changed?
  27. ERIKREAGAN • EECI GETTING SET UP /config/ config.env.php config.master.php config.{ENV}.php

    /public_html/ /system/ /tpl/ 59 Directory and file structure
  28. ERIKREAGAN • EECI GETTING SET UP if ( ! defined('ENV'))

    { switch ($_SERVER['HTTP_HOST']) { case 'focuslabllc.com' : define('ENV', 'prod'); define('ENV_FULL', 'Production'); define('ENV_DEBUG', FALSE); break; case 'ohsnap.focuslabllc.com' : define('ENV', 'stage'); define('ENV_FULL', 'Staging'); define('ENV_DEBUG', FALSE); break; default : define('ENV', 'local'); define('ENV_FULL', 'Local'); define('ENV_DEBUG', TRUE); break; } } 60 config.env.php sample
  29. ERIKREAGAN • EECI GETTING SET UP <?php if ( !

    defined('BASEPATH')) exit('No direct script access allowed'); /** * Development config overrides & db credentials * * Our database credentials and any environment-specific overrides * * @package Focus Lab Master Config * @version 1.1 * @author Erik Reagan <[email protected]> */ $env_db['hostname'] = 'localhost'; $env_db['username'] = ''; $env_db['password'] = ''; $env_db['database'] = ''; $config['webmaster_email'] = '[email protected]'; /* End of file config.dev.php */ /* Location: ./config/config.dev.php */ 61 config.dev.php sample
  30. ERIKREAGAN • EECI GETTING SET UP /** * Template settings

    * * Working locally we want to reference our template files. * In staging and production we do not use flat files * (for ever-so-slightly better performance) * This approach requires that we synchronize templates after * each deployment of template changes */ $env_config['save_tmpl_files'] = (ENV == 'prod') ? 'n' : 'y'; $env_config['tmpl_file_basepath'] = $base_path . '/../tpl/'; $env_config['hidden_template_indicator'] = '_'; 62 config.master.php sample
  31. ERIKREAGAN • EECI GETTING SET UP /** * Debugging settings

    * * These settings are helpful to have in one place * for debugging purposes */ $env_config['is_system_on'] = 'y'; $env_config['allow_extensions'] = 'y'; $env_config['email_debug'] = (ENV_DEBUG) ? 'y' : 'n' ; // Show template debugging if we're not in production $env_config['template_debugging'] = (ENV_DEBUG) ? 'y' : 'n' ; /** * Set debug to '2' if we're in dev mode, otherwise just '1' * * 0: no PHP/SQL errors shown * 1: Errors shown to Super Admins * 2: Errors shown to everyone */ $env_config['debug'] = (ENV_DEBUG) ? '2' : '1' ; 63 config.master.php sample
  32. ERIKREAGAN • EECI GETTING SET UP /** * 3rd Party

    Add-on config items as needed */ $env_config['minimee_cache_path'] = $base_path . '/min'; $env_config['minimee_cache_url'] = $base_url . '/min'; $env_config['minimee_remote_mode'] = 'auto'; $env_config['minimee_debug'] = 'n'; // Disable minimee in dev but not in staging and production $env_config['minimee_disable'] = (ENV == 'local') ? 'y' : 'n' ; // Greeny (auto-updating of upload directory paths) $env_config['greeny_enabled'] = (ENV == 'prod') ? 'false' : 64 config.master.php sample
  33. ERIKREAGAN • EECI 71 DATABASE ISSUES • New custom fields

    alter the DB schema • Installing or updating add-ons can alter the DB schema • Updating EE can alter the DB schema
  34. ERIKREAGAN • EECI DATABASE ISSUES • Custom upload directory paths

    are stored in the DB and cannot be dynamically altered • Relative upload directory paths work sometimes, but not with all add-ons • “Content” is very likely changing in the Production environment while you build and test in your other environments 72
  35. ERIKREAGAN • EECI QUICK TIPS • You need to understand

    EE’s database • Learn about 3rd party add-on’s DB tables • Establish a ruleset for your workflow • Understand that there will be exceptions 74
  36. ERIKREAGAN • EECI FINAL NOTES • These practices make you

    a better developer • They help prepare you to work with a team • They help your team work more efficiently • You can provide a better service to your clients 77