How to run several instances of a rails app with a single code base?

What is the problem?

Sometimes you want to run several instances of the same application on your server. How to easily do this in rails?

The solution :)

Rails offers us the environments, allowing to run an application under different status: development, test or production environment.

We just have to create in the database.yml a specific database connection for each new environment:

prod1:
adapter: mysql
database: prod_one
username: root
password: password

and for another instance

prod2:
adapter: mysql
database: prod_two
username: root
password: password
and to create a specific configuration file 'prod1.yml' in the directory config/environments/.

After this, you just generate the database schema with the following command:

  1. rake db:migrate RAILS_ENV=prod1

And run the server on a specified port:

./script/server -p 4001 -e prod1

Et voilà! an instance running on the specified port (4000).

If you want another one (let's say prod2).

Let's create the database instance... rake db:migrate RAILS_ENV=prod2

./script/server -p 4002 -e prod2 ... and another instance of the same code base is now running on port 4002.

Bliss.

http://dev.af83.com/trackback/20

Pourquoi ne pas laisser une réponse?