I recently needed to deploy a Symfony application to a production server.
After some searching, I noticed Capifony.
Capifony is an extension of Capistrano, specifically built for Symfony projects.
For those who don’t know Capistrano, it is a deployment utility build in ruby, more specifically for ruby projects, but you get a few extensions that you can use to deploy PHP applications as well.
Here is an excerpt about Capistrano: “Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH….Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH”
So the first part of setting up Capifony is to create an SSH connection to the production server. For that I created a public ssh key without a password that I just copied over to the server, so this allows me to connect to the production server from my local machine without having to worry about entering a password every time, and this also makes it easier for Capifony to connect to the server to deploy the application.
On the production server, I needed to make sure that it can connect to my private Github account, which is also accomplished using SSH, so that the latest code can be cloned to the machine.
The last step was just to create the deployment configuration, which look like the following:
set :application, "Application Name" set :domain, "domain_name" set :deploy_to, "/var/www/html" set :app_path, "app" set :deploy_via, :remote_cache set :repository, "github-repository" set :scm, :git # Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, or `none` set :model_manager, "doctrine" # Or: `propel` role :web, domain # Your HTTP server, Apache/etc role :app, domain # This may be the same as your `Web` server role :db, domain, :primary => true # This is where Symfony2 migrations will run set :keep_releases, 3 set :shared_files, ["app/config/parameters.yml", "app/environment.txt"] #set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor"] set :shared_children, [web_path + "/uploads", "vendor"] set :use_composer, true set :update_vendors, true set :update_assets_version, true set :dump_assetic_assets, true set :interactive_mode, false set :writable_dirs, ["app/cache", "app/logs"] set :webserver_user, "apache" set :permission_method, :acl set :interactive_mode, false set :use_sudo, false set :user, "root" default_run_options[:pty] = true # Be more verbose by uncommenting the following line logger.level = Logger::MAX_LEVEL # Custom Tasks after "symfony:cache:warmup", "deploy:set_permissions" # sets the required folders to writable after "deploy:set_permissions", "permission:setowner" # Change ACL on the app/logs and app/cache directories # Sets the directory to the correct owner namespace :permission do task :setowner do capifony_pretty_print "--> Change folder to owner #{webserver_user}" run "chown -R #{webserver_user}: #{latest_release}/" puts_ok end end
And that’s it. So each time I need to update changes, I just use the command
cap deploy
, then all the latest code is pushed to the server.
Capifony also keeps a history of the previous 5 releases, so if something went wrong on deployment, I can just roll back to the previous version.
sgrodzicki
With the latest Capifony it should be:
capifony_pretty_print “–> Change folder to owner #{webserver_user}”