Deploying Yii Application with Capistrano
There's no standard solution to deploy a php application to a server. Many developers have their own self written scripts or tools. If you're looking for something simple and powerful, try capistrano, it's awesome. It might be not so fast to learn and understand the flow of that tool, but it'll be very very useful once you get it. Even though it was originally written for ruby on rails, it isn't so hard to adjust it for any other framework/language.
Let's consider simple example with yii/php application:
$ gem install capistrano
$ clone git@github.com:yiisoft/yii2-app-basic.git
$ cd yii2-app-basic/
$ capify .
Now you have a Capify
and config/deploy.rb
files in your app.
Copy this code sample into your config.rb
,
change :user
, server
settings, load composer and deploy your app:
$ curl -sS https://getcomposer.org/installer | php
$ git add .
$ git commit -m 'Added composer.phar and capistrano config'
$ cap deploy:setup # prepare servers (create basic directory structure etc)
$ cap deploy:check # check if everything requred is installed (git for example)
$ cap deploy
Now setup your http server to look into correct directory. It would be
something like /home/username/www/yii2-app-basic/current/www
(notice current
).
And there we are
Here're some useful links:
- Deployment directory structure: wiki.
(we replaced
logs
,pids
,system
withwww/assets
,runtime
,vendor
in our case) - Original
deploy.rb
code: deploy.rb - An explanation of default deployment behaviour: picture and wiki
Still cannot figure out how to set up logger...
Also you can find more information about capistrano tasks with cap -T
or cap -e deploy:setup
.
Good luck!