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

Deploying Websites with Capistrano

Deploying Websites with Capistrano

How do you currently publish updates to your website? How do you undo changes if you've made a mistake?

Manually uploading files via FTP can lead to mistakes or downtime and are difficult to roll back. Other techniques such as remote repositories or post-receive hooks are better but can limit your ability to control the way updates are applied to the website.

Come learn how to streamline and automate the process of both deploying and rolling back updates to your website with Capistrano, a remote server automation tool.

Presentation given at Front Porch Conference in Dallas, TX
(video available at http://frontporch.io/andrew-turner/)

Andrew Turner

October 07, 2014

More Decks by Andrew Turner

Other Decks in Technology


  1. Deploying Websites with Capistrano
    Andrew Turner, @galenandrew
    Front Porch Conference - Dallas, TX
    October 7, 2014

    View Slide

  2. Common Deployment Methods
    • Server-side Editing
    • FTP Upload
    • File Syncing
    • Live Remote Repositories (i.e. version control on the server)
    • Post-receive Hooks / Webhooks
    • Third Party Deployment Services
    • Continuous Integration

    View Slide

  3. Deployment Challenges
    • Often a manual process
    • High risk of error (easy to break things)
    • Potential downtime during upload / sync
    • No record or log of deployments
    • Typically not well documented or easily distributable
    • Difficult to manage for multiple environments
    • Updates are difficult to reverse
    …especially when a deployment crashes the live site!

    View Slide

  4. Capistrano is a remote server automation and deployment tool
    that provides versioned releases and easy rollbacks.

    View Slide

  5. How Capistrano Works
    • Deployment scripts are stored in your project
    • Executed locally from the command line (Ruby Gem)
    • Connects directly to your server via SSH
    • Checks out code from remote repository to your server
    • Performs automated tasks/commands on server (or locally)
    • Keeps deployment log and versioned releases
    • Provides easy ability to rollback releases

    View Slide

  6. How Capistrano Works
    local server repository
    local connects to server via SSH
    server updates project code from repository
    deploy command is issued on local
    server issues a new release and logs deployment

    View Slide

  7. Installation / Setup
    gem install capistrano
    Install Capistrano
    cap install
    Initialize Capistrano in your project
    Note: Run this command in the root directory of your project as it will create the necessary
    deployment files/folders

    View Slide

  8. Usage
    cap production deploy
    cap production deploy:rollback

    View Slide

  9. Directory Structure: local / project
    ├── Capfile
    └── config
    ├── deploy
    │ ├── production.rb
    │ └── staging.rb
    └── deploy.rb

    View Slide

  10. Directory Structure: server
    ├── current
    ├── releases
    │ ├── 20141007223313
    │ ├── 20140923125109
    │ └── 20140915181947
    ├── repo
    ├── shared
    └── revisions.log
    Note: Make sure to point your web host’s document root to current as it is a symlink to the latest release.
    For example, in the above current would be a symlink (alias) to 20141007223313

    View Slide

  11. Resources
    • Official Capistrano Documentation

    • Official Capistrano GitHub

    • How To Use Capistrano to Automate Deployments: Getting Started

    • WP-Deploy (A framework for deploying WordPress sites using

    • CSS-Tricks: Website Deployments


    View Slide