18th May, 2007

Rails deployment - SCGI

This explains the configuraton
steps for deploying Rails application using Apache and SCGI. This worked
for me.

Hope you already installed the following items.

Fedora Core 4
Apache httpd 2.0.54
Database(mysql/postgres)
Installing Ruby, Gems and Rails:

yum install ruby
yum install ruby-devel
yum install rdoc
yum install irb

mkdir /var/www/files
cd /var/www/files
wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
tar xvf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb

gem install rails –include-dependencies

We have successfully installed Ruby, Gems and Rails. If you want to
check, the status create a application by issuing a command ‘rails
testapp’ and run the in-built
webrick server.(ruby script/server). Check localhost:3000. You should
see the rails app running.

Now Lets start with Apache and SCGI.

yum install httpd-devel
cd /var/www/files
wget http://www.mems-exchange.org/software/files/scgi/scgi-1.9.tar.gz
tar xvf scgi-1.9.tar.gz
cd scgi-1.9/apache2
apxs -i -c mod_scgi.c

This will create mod_scgi.so

Now copy the mod_scgi.so file into Apache modules directory.

After this, you will need the mod_scgi.so module to be loaded. For
this, add the following to your Apache httpd.conf:

LoadModule scgi_module modules/mod_scgi.so

Now we have to install the SCGI gem and also two more gems.

* cmdparse 2.0.0 or greater(gem install cmdparse)

* highline 1.0.1 or greater (gem install highline)

cd /var/www/files
wget http://www.zedshaw.com/downloads/scgi_rails/scgi_rails-0.4.3.gem
gem install scgi_rails-0.4.3.gem

Everything is done. Now create your app and make it known to the
server. If you have already created the app, you can use that too.

rails myapp
cd myapp
>>scgi_ctrl config
<enter password >(Remember this password. You will need this
whenever you stop or restart the server)

Apache httpd.conf file should look like this. Add the following in your
apache configuration file and mention the name of your application.
While giving the document root give the exact path.

<VirtualHost your-ip:80>
AddDefaultCharset utf-8
ServerName www.yourdomain
DocumentRoot /your-switchtower-root/current/public
ErrorDocument 500 /500.html
ErrorDocument 404 /404.html
# handle all requests throug SCGI
SCGIMount /myapp 127.0.0.1:9999
# matches locations with a dot following at least one more characters,
that is, things like *,html, *.css, *.js, which should be delivered
directly from the filesystem
<LocationMatch \..+$>
# don’t handle those with SCGI
SCGIHandler Off
</LocationMatch>
<Directory /your-switchtower-root/current/public/>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Your public/.htaccess file should look like: (This is inside your rails
application)

Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /rails/dispatch.cgi/$1 [QSA,L]
ErrorDocument 500 “<h2>Application error</h2>Rails
application failed to start properly”

To start SCGI, get inside your application.

cd myapp
nohup scgi_ctrl start &

Now restart apache

>>apachectl restart

Visit the URL of your site and you should see the welcome screen. Next,
visit URL/myapp and the rails app should be available
there.

Leave a response

Your response:

Categories and Tags

Advertising