I’ve been doing some work with NGINX of late and anyone familiar with CakePHP will know that it ships out of the box with Apache .htaccess files to make sure that the URL’s are devoid of there query string.

Anyway, enough talk, if you want to host cakephp on NGINX, you’ll need to use a vhost like so:



    server { 
        listen       80;
        server_name  somedomain.com;
        access_log  /var/www/logs/somedomain.access.log  main;
        error_log   /var/www/logs/somedomain.error.log info;
        rewrite_log on;

        # rewrite rules for cakephp
        location / {
          root   /var/www/sites/somedomain.com/current;
          index  index.php index.html;

          # If the file exists as a static file serve it 
          # directly without running all
          # the other rewite tests on it
          if (-f $request_filename) { 
            break; 
          }
          if (!-f $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;
            break;
          }
        }

        location ~ \.php$ {
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME \
          /var/www/sites/somedomain.com/current$fastcgi_script_name;
          include fastcgi_params;
        }
    }

WebGen is a groovy little tool that makes building HTML sites a lot simpler, and makes maintenance a lot more efficient via clever templating. I wont labour the pro’s and con’s of the project here, I’ll just get on with explaining how to deploy version webgen sites using our good friend Capistrano.

First off, install Capistrano:

$ sudo gem install capistrano -y

Next, we need to prepar our webgen dir with all the relevant deployment information. All these commands presume you have ‘cd’ to the webgen project directory Capistrano provides a simple way to do this

$ mkdir config
$ capify .

Next we need to setup our new deploy.rb file, mine looks a little something like this:

  

set :application, "yourapplication.com" 
set :repository,  "svn://yourhost/path/to/webgen/site/output" 

# If you aren't deploying to /u/apps/#{application} on the
# target servers (which is the default), you can specify 
# the actual location via the :deploy_to variable:
set :deploy_to, "/var/www/sites/#{application}" 

# If you aren't using Subversion to manage your 
# source code, specify your SCM below:
# set :scm, :subversion
set :user, "deploy" 
set :svn_user, "badger" 

role :app, "yourapplication.com" 
role :web, "yourapplication.com" 
role :db,  "yourapplication.com", :primary => true

# Overrides the default task supplied by cap, as this 
# is a static site there are no mongrel's et al 
# that need restarting
desc "Deploy webgen site" 
deploy.task :restart do
  puts "Using webgen, so nothing to restart" 
end

# also, because we have configured logging via our HTTP 
# server (e.g. nginx, apache etc) we have no need for this 
# part of the deployment phase to we again, just override it
# with an arbitrary message
desc "Override default cap behavior for finalize_update" 
deploy.task :finalize_update do
  puts "We dont need no stinking logs..." 
end

Now, all being well, we need to setup the server to respond to cap:

$ cap deploy:setup

Then we should be able to deploy our project with no problems!

$ cap deploy

I hope this was of use to someone, somewhere, sometime :)