I just want share my experience when my first time deploy rails application using FastCGI. Here's step by step of installation fastCGI for your rails application.
preparation offline
- Already have Database and hosting server in 1 package with linux OS
- Already Complete ruby on rails application
- export your database to file or dump your database to external file.
- Go to your appz_name/config/environment.rb. You need to uncomment the following line to confirm you're in production mode:
ENV['RAILS_ENV'] ||= 'production'
- Modify your appz_name/public/.htaccess file by changing some parts to the following below:
# General Apache options
#AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
...
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
#if you seeRewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
#in your file, change it to like below
- Set up your database in your hosting or db server online, create 3 databases, after that match it to appz_name/config/database.yml if you found difference setting, fix it. Your database.yml must be the same like your setting in database server including database password, username, database name.
- Now, the last step, go to appz_name/public you will see 3 files with named dispatch*.*. Open them and change their first line to be
#!/usr/local/bin/ruby
- edit your routes.rb in appz_name/config/and uncomment :
map.connect '', :controller => "your_main_controller_name"
- delete or rename your index.html in appz_name/public
- Attach or archive your app project folder in zip or tar.tgz.
preparation online
- use your putty to access your shell console account of your hosting. After logged, Go to your /home/username upload your attached app project folder to this area then extract it.
- your will get your project rails folder from your extracted file.
- Back up your existed public_html :
mv ~/public_html ~/public_html_backup
- I forget to tell you the most important thing, that is you must chmod 755 dispatch*.* in your /home/username/appz_name/public
- after that back to /home/username and run it:
ln -s ~/yourapp/public ~/public_html
Done !!! If you did all those steps correctly you will not see Application Error message in your browser. Have nice try and good luck.