Capistrano is an open source tool for running scripts on multiple servers. It’s primary use is for easily deploying applications. While it was built specifically for deploying Rails apps, it’s pretty simple to customize it to deploy other types of applications. capifony is a deployment recipes collection that works with both symfony and Symfony2 applications. Taken from capifony.org
In order to install capifony you have to use RubyGems. RubyGems is a package manager for ruby programs.
gem install capifony
On OSX you might need to use
sudo gem install capifony
Go to folder of your Symfony2 application
Now we have to initialize capifony.
This will create two files Capfile and deploy.rb. The Capfile is a capifony configuration file and deploy.rb is a file where you write your server information.
You can ignore Capfile but we have to modify the deploy.rb file.
It can be found in
Now if you were to open that file its contents should look something like this.
Replace the contents of deploy.rb with the following code:
__1__ with your application’s name. Example: myApp
__2__ with your domain name. Example: myapp.com
If you’re unsure what to write on
__3__ just use
ssh to connect to your server and afterwards
see what’s your folder’s name.
__4__ with your server’s username
__5__ with your server’s password
__6__ with your port number. This step is optional and you should fill it out only if you’re not using default ssh port.
Also don’t forget to remove
# to uncomment that part of code.
__7__ with your git repository. Example email@example.com:someRepo.git
__8__ you write here your folder’s name you want to share. This part will be explained in more detail later.
Now after we successfully modified our deploy.rb file we have to prepare our server for capifony.
ssh to log on to your server.
You should be /home/_some_name
Create folders called releases and shared.
When application is deployed capifony will clone your git repository in releases folder.
In deploy.rb file there was line
set :keep_releases, 3 you can change that number to any amount you want.
After your git repository has been cloned it will get the latest release and symlink it on to current folder. Contents of your shared folder will be symlinked to your current folder.
This is excellent when you have let’s say user uploaded images. This will enable you to share your images across releases.
So if you were to replace
__8__ with something like
web/images that would symlink your images folder in your
current release web folder.
The shared folder structure should be something like this:
shared/app/config/parameters.yml shared/web/.htaccess shared/web/images
Exit your ssh connection and position yourself to your symfony2 application:
And now let’s deploy our symfony2 application.
Give it few minutes to complete and now you have to do one more final step.
ssh to your server and symlink current/web to your public_html.
If you already have public_html folder you have to first remove it.
rm -rf public_html
ln -s current/web public_html
You will have to do this last part of configuration only the first time.
For future deploys you only need to write
Capifony has lots of additional features to list them all write:
I personally find very useful
cap deploy rollback option.
Let’s say you deploy your application but there’s some bug in code so while you’re fixing it you can
cap deploy rollback to revert to the previous release.
I believe I’ve demonstrated through this short tutorial just how easy it is to deploy your symfony2 applications using capifony. Sure you might have some trouble configuring all this the first time but in the long run it will pay off.
This post is on GitHub. If you spot any errors please do a pull request.
comments powered by Disqus