The way developers deploy code to web servers is changing. Gone are the days of remembering which files you’ve changed and manually dragging and dropping files around an FTP client. This deployment method is risky - it’s easy to miss a file and therefore break your entire application. FTP is also insecure - no encryption is used when sending your login credentials to the server, or for file transfers. Also, what happens when a visitor is using your application whilst you are uploading - some files might not be fully uploaded and your application will fail.

There are numerous alternatives to FTP, but I’m going to show you how to get started with Capistrano “A remote server automation and deployment tool written in Ruby”. In short, Capistrano allows you to write scripts to execute code on remote servers (and your local machine). We can use this technique to pull code from a version control repository onto our web server and run other commands.

Getting Started

Before we get started, I’m going to make a few assumptions:

  • You’re using a Mac (although this should work fine for Linux users too) and have some basic knowledge of using the terminal
  • Your code is kept in version control - if it’s not, it should be (I recommend GIT)
  • You’ve got a dedicated server or VPS to host your application on (I strongly recommend Linode)
  • You use SSH keys to connect to your server(s)
  • You have Ruby installed on your local machine (see the official instructions)
  • You won’t be trying this out on a live production application / site (you will have some downtime as you will need to change the path to your web root directory)

First off, install Capistrano by running the following command in your terminal:

gem install capistrano

Next up we’re going to install another gem that makes Capistrano a bit friendlier for non-Rails projects, Lee Hambley’s Railsless Deploy:

gem install railsless-deploy

That’s it - everything we need should now be installed.

#web development #php

Deploy your PHP website with Capistrano
1.40 GEEK