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:
and for another instance
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:
And run the server on a specified port:
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.