Deploying a Symfony application with Capistrano

source 'https://rubygems.org'
#…
gem 'capistrano-symfony', '~> 0.4'
# Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/symfony'
########################
Setup project
########################
set :application, "hello-world-medium"
set :repo_url, "https://github.com/groupname/repository.git"
set :scm, :git
#########################
Setup Capistrano
#########################
set :log_level, :info
set :use_sudo, false
set :ssh_options, {
forward_agent: true
}
set :keep_releases, 3
#######################################
Linked files and directories (symlinks)
#######################################
set :linked_files, ["app/config/parameters.yml"]
set :linked_dirs, [fetch(:log_path), fetch(:web_path) + "/uploads"] set :file_permissions_paths, [fetch(:log_path), fetch(:cache_path)] set :composer_install_flags, '--no-interaction --optimize-autoloader'
namespace :deploy do
after :updated, 'composer:install_executable'
end
#######################
Setup Server
########################
server "pro.company.com", user: "sshuser", roles: %w{web}
set :deploy_to, "/path/to/your/deployment/directory"
#########################
Capistrano Symfony
#########################
set :file_permissions_users, ['www-data']
set :webserver_user, "www-data"
#########################
Setup Git
#########################
set :branch, "master"

Working with custom tasks

Dir.glob('config/tasks/*.cap').each { |r| import r }
namespace :dependencies do
desc 'npm dependencies & gulp tasks'
task :yarn
run_locally do
execute "yarn install && gulp prod"
end
end
desc 'Upload compiled dependencies'
task :upload do
on roles(:all) do |host|
upload! "#{fetch(:web_path)}/css", "#{release_path}/#{fetch(:web_path)}", recursive: true
upload! "#{fetch(:web_path)}/js", "#{release_path}/#{fetch(:web_path)}", recursive: true
end
end
namespace :deploy do
after :starting, 'composer:install_executable'
after :updated, 'symfony:assets:install'
after :updated, 'dependencies:yarn'
after :updated, 'dependencies:upload
'
end

--

--

--

IT Manager at Demium. Former CTO of different companies and startups. Father of one. Health learning lover.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Refactoring Picasso 2nd Part —the confluence of things

ACL —Extending Permissions on Linux

One reason why your Agile implementation is failing

Point cloud rendering with Unity

Point cloud Physic simulation

Can low code “replace” developers?

Vabble — Development Status — October Edition

Deploy .Net Core App to Heroku

File-Storage-In-The-New-World.txt

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jon Torrado

Jon Torrado

IT Manager at Demium. Former CTO of different companies and startups. Father of one. Health learning lover.

More from Medium

Laravel-Code Analysis using SonarQube & SonarScanner

Laravel: Use Increment IDs , UUIDs, ULIDs as primary key or optional field for the Eloquent model

How to resolve laravel — The stream or file “/storage/logs/laravel.log”

HTTPS local web server with PHP and ngrok on Mac

ngrok UI in terminal displaying public URL and metrics about connections