百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

symfony

> 编程语言
开源

用于部署 Symfony 标准版的 Capistrano 任务

353 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

用于部署 Symfony 标准版的 Capistrano 任务

Capistrano::Symfony

Symfony 4 specific tasks for Capistrano v3 (inspired by capifony).

It leverages the following capistrano tasks to deploy a Symfony app

  • https://github.com/capistrano/composer
  • https://github.com/capistrano/file-permissions

Version information

Version 1.x

This version is built for Symfony 2 and 3.

Go to Version 1 documentation.

Version 2.x

This version is built for Symfony 4.

You are currently on the Version 2 branch.

Installation

Specify your dependencies:

# Gemfile
source 'https://rubygems.org'
gem 'capistrano',  '~> 3.11'
gem 'capistrano-symfony', '~> 2.0.0'

Install your dependencies:

bundle install

When capistrano and capistrano-symfony is installed. Run the following command to set up your local files:

cap install

Make Capistrano aware of 'capistrano/symfony' by requiring capistrano-symfony in your new Capfile after require "capistrano/deploy".

ruby
# Capfile
# ...
require "capistrano/symfony"

If you use composer you might want this:

require "capistrano/composer"

Usage

cap staging deploy
cap production deploy

Settings

If you are using a standard Symfony Flex application that follows the best practises then you do not need to change/add anything to your deploy.rb other than what is required from Capistrano.

We do however expose the following settings (shown with default evaluated values) that can be modified to suit your project. Please refer to lib/capistrano/symfony/defaults.rb to see exactly how the defaults are set up.

…

Flow

capistrano-symfony hooks into the flow offered by capistrano. It adds to that flow like so

  • symfony:create_cache_dir
  • symfony:set_permissions
  • symfony:cache:warmup
deploy
|__ deploy:starting
|   |__ [before]
|   |   |__ deploy:ensure_stage
|   |   |__ deploy:set_shared_assets
|   |__ deploy:check
|__ deploy:started
|__ deploy:updating
|   |__ git:create_release
|   |__ deploy:symlink:shared
|   |__ symfony:create_cache_dir
|   |__ symfony:set_permissions
|   |__ symfony:make_console_executable
|__ deploy:updated
|   |__ symfony:cache:warmup
|__ deploy:publishing
|   |__ deploy:symlink:release
|   |__ deploy:restart
|__ deploy:published
|__ deploy:finishing
|   |__ deploy:cleanup
|__ deploy:finished
    |__ deploy:log_revision

File permissions

Set the permission_method variable to one of :chmod, :acl, or :chgrp in your deploy.rb to handle the common scenario of a web user and the deploy user being different.

Both will need access to the files/directories such as var/cache and public/uploads (if you handle uploads). Set file_permissions_users to your webserver user

Example:

# deploy.rb

set :permission_method, :acl
set :file_permissions_users, ["nginx"]
set :file_permissions_paths, ["var", "public/uploads"]

Note: Using :acl requires that setfacl be available on your deployment target. Note: If you are getting an error like setfacl: Option -m: Invalid argument near character 3,
it means that the users in file_permissions_users do not exist on your deployment target.

See the symfony documentation and the file permission capistrano plugin for reference.

Integrated common tasks

The following common tasks are available:

  • symfony:assets:install

So you can use them with hooks in your project's deploy.rb like this:

ruby
after 'deploy:updated', 'symfony:assets:install'
before 'deploy:updated', 'symfony:build_bootstrap'

Using the Symfony console

A task wrapping the symfony console is provided, making it easy to create tasks that call console methods.

For example if you have installed the DoctrineMigrationsBundle in your project you may want to run migrations during a deploy.

ruby
namespace :deploy do
  task :migrate do
    symfony_console('doctrine:migrations:migrate', '--no-interaction')
  end
end

If you want to execute a command on a host with a given role you can use the Capistrano on DSL, additionally using within from Capistrano will change the directory

ruby
namespace :deploy do
  task :migrate do
    on roles(:db) do
      symfony_console('doctrine:migrations:migrate', '--no-interaction')
    end
  end
end

Using composer

If you use composer you can install capistrano/composer. Here are some short instructions. Read more at capistrano/composer.

First run the following command to download the library:

gem install capistrano-composer

Then make sure your Capfile includes the following:

require 'capistrano/composer'

To download the composer.phar executable add the following to your deploy.rb:

# First define deploy target: 
set :deploy_to, "/home/sites/com.example"

# Install composer if it does not exist
SSHKit.config.command_map[:composer] = "php #{shared_path.join("composer.phar")}"

namespace :deploy do
  after :starting, 'composer:install_executable'
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言