Configuring A2 to run your Ruby on Rails Application
This document is for experienced Rails developers who wish to install their working Rails application on A2. This document assumes that the reader is skilled in Rails application development and environment configuration.
1) Create The Rails Application Using cPanel, create a new Rails application with the name that you want to use. This will allocate a port number for your application. Failure to use the cPanel may result in your application conflicting with another application for the same port number. Don't start it at this point.
After you've created the new rails application, SSH to your server, CD to the directory that was created with the new application and "rm -r" that puppy. All you need is the directory and you can easily re-create that should you accidentally blow it away. Practice safe directory removal!
2) Create your database Create the database, database user and password for your application database. Don't forget that you will likely want to have a development, production and test database installation so that you can use all the debugging techniques you have at your disposal when debugging your application.
3) Transfer your Rails Application
Using your favorite technique (FTP, SVN, git, etc.) transfer your application files to the empty application on your server.
4) Prepare your Environment 4.1) Determine your current environment Run "gem environment" to identify your current environment. You should see something like:
RubyGems Environment:
- VERSION: 0.9.2 (0.9.2)
- INSTALLATION DIRECTORY: /usr/lib64/ruby/gems/1.8
- GEM PATH:
- /usr/lib64/ruby/gems/1.8
- REMOTE SOURCES:
- http://gems.rubyforge.org
You are going to add values so that you can install gems locally and have them found. There are two placed where this will be done: 1 - At the shell level 2 - At the rails level
4.2) Configure the shell
Confirm that you have a 'ruby' directory off your home directory. The ruby directory should have a 'bin', 'gem', and 'lib' subdirectory. Contact A2 if you do not have this directory.
Extend your .bash_profile configuration with the following:
PATH=$PATH:$HOME/bin::$HOME/ruby/bin GEM=$PATH::$HOME/ruby/gems:/usr/lib/ruby/gems/1.8
export PATH export GEM export GEM_HOME=:$HOME/ruby/gems export GEM_PATH=:$HOME/ruby/gems/gems:/usr/lib/ruby/gems/1.8
Save the .bash_profile and use "cd; source .bash_profile" to load these changes.
Now, modify the .gemrc file in your home directory. It will likely look something like this:
--- gem: --remote --gen-rdoc --run-tests gemhome: /home/<YOUR_NAME>/ruby/gems gempath: []
rdoc: --inline-source --line-numbers
Modify the "gempath" variable to be the following:
gempath: - /home/<YOUR_NAME>/ruby/gems - /usr/lib/ruby/gems/1.8
Obviously (but sometimes not entirely obviously), replace <YOUR_NAME> with your login name.
4.3) Configure the rails environment
Now, CD to your RAILS_ROOT. By default is is likely $HOME/etc/rails_apps/<APP_NAME>.
Edit your database.yml file to match the database name, schema name, user name and password you used when creating the database.
Modify config/environment.rb. Add the following to the top of the file:
ENV['GEM_PATH'] = '/home/<YOUR_NAME>/ruby/gems:/usr/lib/ruby/gems/1.8'
$:.push("/home/<YOUR_NAME>/ruby/gems")
At this point, you should be able to install your own gems with 'gem install' or 'rake gems:install'
You should also be able to "rake db:migrate"
4.4) Starting Mongrel
The next step is to start mongrel. The author has found that it often required a ticket to A2 to in order for the cPanel initiated mongrel_rails to find the locally installed gems. However, starting mongrel_rails from the command line has proven successful. Use the following command structure:
mongrel_rails start -d -p <PORT> -P /home/<YOUR_NAME>/etc/rails_apps/<YOUR_APP>/log/mongrel.pid
NOTE: you can find the port number from the cPanel. Just click on "Create Rewrite" to see what port has been assigned to your appliation.
5) Connect to your application
Follow the instructions at https://support.a2hosting.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=461 to create a sub-domain and Custom An Essay Papers Online connect your application via that sub-domain.
NOTE: When you create the redirect, cPanel will create a .htaccess in your sub-domain directory (typically in ~/public_html). You need to modify the .htaccess so that all requests are routed to your rails app.
Look for this type of line:
RewriteRule ^/?$ "http\:\/\/127\.0\.0\.1\:XXXXXX%{REQUEST_URI}" [P,QSA,L]
Where "XXXXX" is the port upon which your rails app is running. Notice that this RewriteRule won't match anything other than the root URL. Therefore you need to modify it like so:
RewriteRule ^/?.*$ "http\:\/\/127\.0\.0\.1\:XXXXX%{REQUEST_URI}" [P,QSA,L]
Note the ".*" to match all URI's within the root URL