Capistrano

Capistrano is an open-source tool for executing scripts at the remote servers. Most commonly, it is used for deploying apps via SSH connection. Capistrano is written in Ruby as a component of the Ruby on Rails framework, therefore, it is widely used for Ruby apps deployment. Nevertheless, it can easily work with other programming languages, e.g. PHP.

Thus, in this instruction we will discover how to deploy a PHP application remotely, via the Capistrano tool. Initially you will need:
  • an already created PHP environment with Apache application server;
  • SSH public key generated and added to your GPUonCLOUD dashboard;
  • GIT repository with PHP application you would like to deploy (for now Capistrano 3 tool supports GIT VCS type only);
  • local copy of this project at your computer.

Let’s get started!

Note that all of the commands below should be executed at your local machine’s user, similar to one you’ve used during SSH key pair generation, in order to avoid permission/connection errors.

Install Capistrano

1. For using Capistrano, you need to have Ruby installed at your local computer. Therefore, execute the appropriate command:

apt-get install ruby rubygems

2. Then, install the Capistrano tool by entering the following command:

gem install capistrano

3. Ensure you have the config folder in the local directory with your project (as it is a default folder with configurations for Ruby on Rails). Create this folder if you don’t have it.

mkdir {path_to_your_project}/config

Capify Your Application

After installation, you need to capify your application, i.e. configure Capistrano for app deployment. To do this, navigate to the root folder of your local PHP project and execute the next command:

cap install
This will create new files and directories in your project:
  • Capfile is the main Capistrano file that takes care of the required configs and globs for custom tasks.
  • config/deploy/ folder with two files (staging.rb and production.rb) for an environment’s specific deployment settings.
  • config/deploy.rb Ruby script which contains application configurations and Capistrano instructions.
  • lib/capistrano/tasks/ folder for your custom tasks.
Tip: As an option, you can try the dedicated capistrano-GPUonCLOUD gem, maintained by gerado-navarro, for automating your Rails apps’ deployment to GPUonCLOUD PaaS&IaaS.

Set Custom Configurations

1. Navigate to the config/deploy.rb file and configure it corresponding to your settings. Initially it looks like following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<div class=”container” style=”max-width: 1425px; width: 787px; bo