I recently had to write a recipe to set up instances of mod_rails apps for apache2. The goal of this process is to have a server that has apps hosted at http://server/app1, http://server/app2, etc.
The recipe is going to be used to create a puppet script, but it could also be boiled down to a ruby or shell script to easily create app instances for anyone’s use.
Assumptions and Server Setup
All of this is done as sudo or root
The OS has apache2, mysql, sqlite3, ruby, rubygems, git-core and
subversion installed
The gems sqlite3-ruby, mysql, rails, capistrano are installed
If apache2 is not yet configured with mod_rails, do the following:
Create /etc/apache2/mods-available/mod_rails.conf and put the following in it:
$ apache2ctl graceful
$ wget http://localhost/<username> --server-response --spider # this should return 200 OK
Create a mysql user and databases for the app
1
$ for db in production test development; do mysql -u root -pMYSQLPASS -e "grant all privileges on <username>_$db.* to '<username>'@'localhost' identified by '<userpassword>'; create database <username>_$db;" done
Copy template capistrano deployment files into their home/<username>/rails directory
At this point the application will be available running at http://hostname/<username>
With one of the deploy.rb files, a savvy rails user can deploy their application to the server with capistrano
A less savvy rails user can connect via ssh and checkout their their rails app to someplace in their home, then symlink it to the ~/rails/app directory