Capistrano: tail -f log

Want to tail a production log with Capistrano?

If you type Ctrl C, you get a load of warnings in your console. Here’s how to fix that:

desc “tail production log files” 

task :tail_logs, :roles => :app do

  trap(“INT”) { puts ‘Interupted’; exit 0; }

  run “tail -f #{shared_path}/log/production.log” do |channel, stream, data|

    puts  # for an extra line break before the host name

    puts “#{channel[:host]}: #{data}” 

    break if stream == :err



Rails and Nginx: caching

Rails using Phusion Passenger is actually pretty quick after Passenger has first loaded.

And adding caching makes it pretty zippy.

Adding caching via Nginx makes it super fast. Cached pages bypass Rails and are served directly by Nginx which is incredibly fast.

Here’s a guide to using Rails with Nginx. Assuming you’ve got both installed, you need to:

1. add a flag to enable, e.g.:

config.action_controller.perform_caching = true

2. add caches_page


class ProductsController < ActionController


  caches_page :index


  def index

    @products = Products.all



Rails guide on page caching:

Nginx page caching:

Note that this assumes your cache will be in the public/ folder. For a non-standard page cache directory you’ll need to use mod_rewrite.

Apache: Client denied by server configuration

This error means that the access to the directory on the hard disk was denied by an Apache configuration. It could be that access was denied due to an explicit deny directive or due to an attempt to access a folder that is outside of the DocumentRoot. It can also happen when you are proxying and there’s no access configured for the proxied location. And it is the default response to a PUT request.

To fix this problem, look at the line in your ErrorLog, to find out which folder it is trying to access. 

If a <Directory> block already exists for that folder, make sure it is set to allow access as necessary. If not, add a <Directory> block to your Apache configuration file, allowing access as required. See the example below for folder /usr/local/awstats/htdocs.

<Directory /usr/local/awstats/htdocs>

  Order allow,deny

  Allow from all



Capistrano: Passenger

Updating Passenger via Capistrano requires a few commands. Here’s all of them on 1 line with an explanation below:

c; git commit -am “some message”; git push origin master; cap deploy:update; cap deploy:restart

c => this is an alias to clear. It clears the screen so new output isn’t confused with old output

git commit => this commits to the local git repo

git push => pushes to github

cap deploy:update => updates the server with the new code (from github)

cap deploy:restart => Passenger won’t recognise the new files until you restart it. This does a ‘touch tmp/restart.txt’ 

Passenger: specifying the environment

Passenger runs in production by default.

To run in development, update your Virtual Host and set the Rails Environment variable, e.g.:

RailsEnv development

e.g. here’s my full Passenger VirtualHost config:

<VirtualHost *:80>


        # !!! Be sure to point DocumentRoot to ‘public’!

        DocumentRoot “/path/to/public”

        RailsEnv development

        <Directory “/path/to/public”>

                Order allow,deny

                Allow from all

                # This relaxes Apache security settings.

                AllowOverride all

                # MultiViews must be turned off.

                Options -MultiViews



See also this discussion:

and this:

vim tips

Indent multiple lines quickly

Use >


e.g. to indent 5 lines use:




To mark a block of 3 lines and indent in vim, use:



Repeat last change

Use .

e.g. if deleting a word with dw then just hit .to repeat.


Split screen and view another file

:vsplit <file>