Jan 22, 2011

Automated deployment setup (Capistrano)

It is really tricky in order to automate the deployment. First, install Capistrano on your local machine:

gem install capitrano

then,

capify /project_dir

It will create a file deploy.rb under config folder. Now make it look like this:

set :application, "CollegeSwap"
set :domain, "72.26.225.10"
set :repository, "git@github.com:tanin47/CollegeSwap.git"

set :use_sudo, false
set :deploy_to, "/#{application}"
set :scm, "git"

set :user, "deploy"

set :branch, "master"

role :app, domain
role :web, domain
role :db, domain, :primary => true

# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts

namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end

Now go to your server and clone the project. On the local computer, you can type 'cap deploy' to re-deploy the project.

There will be some issue about permission. You can try setting the deploy user and nignx user to be the same user. That's probably the simplest way.

Or you can set them to be in the same group. Give the access to the group instead by 'chown -R :nginxgroup /CollegeSwap'.

Then, you need to type 'chmod g+s /CollegeSwap'; every file created under this dir will inherit permission from its parent.

And that's it. you're good to go.

One last thing, do not forget to 'chmod -R 777 /CollegeSwap'

Nginx: 403 Forbidden

When you found this weird error while using Nginx with Passenger, there can be of 2 causes.

First, try playing with permission stuff.

If that does not help, it might be because of your config file.

you config file should not look like this:

server {
listen 80;
server_name wikicards.org;
access_log /var/log/nginx/wikicards.access.log;
passenger_enabled on;

location / {
root /var/apps/wikicards/public;
index index.html index.htm;
}
}

* location and passenger_enabled on should not be in the same block. Remove the location block and that's it.

Nginx installed !

And now we have the fastest web server running on our machine.

It's pretty simple. You don't need to install Nginx first.

just install Passenger with 'gme install passenger', then type 'passenger-install-nginx-module'

It will tell you to do something with the config file. Just don't forget to do it.

And that's it.

I've just read that Nginx is much faster than Apache

I'm switching to it right now.

--------------------------------------

I cannot get Nginx to run faster than Apache. Maybe I don't know the appropriate configuration for it.

Anyway, right now I'm using Heroku instead.

Apache 2.2 + Phusion Passenger

Apache 2.2 + Phusion Passenger is awesome. I have been using WEBrick for a while. It was friggin' slow. There are also other awesome alternatives: Thin, Mongrel, and nginx with unicorn.

Nginx + Unicorn is better at serving customer with high-speed internet connection. Actually, Unicorn is said to strictly serve local clients only, e.g., another program within the same computer. Therefore, Unicorn is good for a Rack-based application. You can read its well-written philosophy here. It also states why Nginx, not Apache, is the only webserver that is appropriate for Unicorn.

(There is an HTTP server, Rainbow, which strictly serves remote, low-speed client.)

So, Unicorn is not our appropriate solution.

Thin is said to be very faster. Nevertheless, this benchmark said that Passenger is the fastest web server among Thin and Mongrel.

(And some people have said that installing Mongrel is pains in the ass)

I haven't verified it myself, and I won't do it. I'm just gonna take it for grant :D

---------------------------------------------------

Ok, so this is how you install Apache with Passenger.

First, install Apache. This is pretty damn easy. If you cannot do it yourself, I suggest you should change your job.

Second, install passenger. (You need gem, just don't do it manually) type 'gem install passenger'.

Then, you type 'passenger-install-apache2-module'. If it does not detect your apache, then try to set the option '--apxs2-path'.

On the screen it will tell you to copy some text to Apache configuration file and how to point to the rails application. That's it !

Jan 18, 2011

libmysql for Ruby 1.8.6 must be a special one

You cannot just get it from MySQL's bin folder. It simply does not work. You need a specific libmysql.dll.
(I have it in my gmail. You can request from me.)

Jan 15, 2011

2 Hackathons reflected

So many mistakes we have done. Most of the mistakes came from me. It's worth to list all the mistakes that we have done.

The first big mistake that we have done is to greedily draw the scope. Our scope of HopIn was initially friggin' big, vertically and horizontally. Right now I have a theory that a scope has two dimensions on it: Vertical and Horizontal. Scope should be devised toward vertical direction, at least, in the beginning.

To extend scope vertically means that we are building the application toward our goal regardless of how many people we polarize. To extend scope horizontally means that we are building the application to support more people. An example is: when we build an application for trading; if we go for supporting more numbers of currencies, that's extending the scope horizontally. If we go for supporting 'shipping cost calculation', that's veritical extension.

Within a day, we can only finish a really small vertical scope. The lesson here is to draw a small vertical scope. If the scope is to wide and tall, phrase it.