Capistrano
Deploy Applications with Capistrano
Capistrano is an open-source remote automation tool commonly used to deploy applications over SSH. Although it is written in Ruby and frequently associated with Ruby on Rails, it can also be configured to deploy PHP applications to the platform.
Prerequisites
Before configuring Capistrano, prepare the required environment, repository, and SSH access components.
Run commands as the correct local user
Execute the commands under the same local user account that was used to generate the SSH key pair. This helps prevent permission and SSH connection errors.
Install Capistrano
Install Ruby and RubyGems on the local computer.
Install Capistrano through RubyGems.
Ensure that the project contains a config directory. Create it when it does not already exist.
Capify the Application
After installing Capistrano, initialize its deployment structure in the root directory of the local PHP project.
The command creates the standard Capistrano files and folders:
Configure config/deploy.rb
Open config/deploy.rb and update the application, repository, deployment directory, source-control, output, and terminal settings.
Set the application name
Set the Git repository URL
Repository SSH access
The SSH public key associated with the local private key must also be attached to the Git account. Otherwise, deployment may fail with a permission-denied error.
A public HTTPS repository URL can be used when repository authentication is not required:
Set the deployment directory
Use the default web-root location for the platform PHP application server:
Enable the required Capistrano options
Replace the default deployment tasks
Remove the default task block beginning with namespace :deploy do and replace it with the following tasks:
Additional options, such as a repository branch, linked files, or linked directories, can be included when required by the application.
Configure config/deploy/staging.rb
Open config/deploy/staging.rb and replace the default server identities with the platform SSH connection values.
Update the role entries
For each role line, replace deploy@example.com with the platform SSH identity in this format:
The application, web, and database role entries should use the same target when the application is deployed to a single Apache node.
Update the server definition
Specify the SSH gateway hostname and use the combined nodeid-uid value as the user.
Set the SSH port
Save the file
Save all staging configuration changes before continuing to the Capfile and SSH-agent configuration.
Update the Capfile
Open the Capfile in the root of the local project and add the following line:
Configure the SSH Agent
Confirm that ssh-agent is running on the local system.
Add the private SSH key that corresponds to the public key uploaded to the platform dashboard.
Verify that the required key is loaded.
Check the Configuration
From the root directory of the local project, run the Capistrano deployment check:
Capistrano connects to the remote application container, prepares the required deployment folders, and validates the local and remote requirements. Missing tools, files, permissions, or configuration details are reported as errors.
Deploy the Application
After the configuration check completes successfully, deploy the application from the project root:
Capistrano downloads the repository, creates the release structure, updates the current-release link, creates the platform web-root symlink, and restarts Apache according to the configured tasks.
Deployment verification
Open the environment URL after deployment and confirm that the application loads correctly.
