Ruby on Rails
HowtoInstallAndRunRubyOnRailsOnPlesk (Version #138)

These instructions were developed on a server with:
Virtuozzo VPS running Red Hat Enterprise 3, Plesk 7.5.4, and Apache 2.0.40.

However, these instructions have been used with other Plesk set-ups (please see comments at the end, and “gotchas” in the instructions for more details):
Fedora Core 4 & Plesk 8
Fedora Core 2 & Apache2 & Plesk
Virtuozzo VPS running CentOS 4.4, Plesk 8.0.1, and Apache 2.0.52.

These instructions are based on the following sources:
http://wiki.rubyonrails.com/rails/pages/HowtoInstallAndRunRubyOnRailsOnCpanel
http://soapboxconfessional.com/articles/2005/05/25/rails-on-plesk
http://wiki.rubyonrails.com/rails/pages/Ruby+and+Rails+on+Red+Hat+Enterprise+Linux

Many Plesk installations are quite minimal as you are not expected to be fooling around with the server much via commandline. So if the Gotchas don’t help you then please pay attention to the error messages and use the logs. Most things which won’t compile will be missing library files and/or -devel packages.

These instructions assume you are running as a superuser.

-

#Step(s) 0:
#MediaTemple

On Media Temple you may need to get the development kit installed and set up the root password. Also the server does not come with pico or Nano (text editors).

In /usr/local/src

wget <a href="http://www.nano-editor.org/dist/v1.2/nano-1.2.5.tar.gz">http://www.nano-editor.org/dist/v1.2/nano-1.2.5.tar.gz</a>
cd nano-1.2.5
./configure 
make
make install

#Check for zlib

This shouldn’t be necessary for most most people so you can skip this step. However, it may be wise to make sure you have zlib installed before you continue. If you do not have zlib then you will get an error message “require__�? when you try to install rails in step 3.

The way I did it was to create a file called phpinfo.php in my httpdocs with the following:

*

<?php

// Show all information, defaults to INFO_ALL
// phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

*

Naviagte to http://www.yourtestdomain.com/phpinfo.php and you should see zlib meantioned somewhere. If not you will need to install it from http://www.gzip.org/zlib/

-

Gotchas

On my mediatemple AS (application server) there wasn’t even GCC installed. I had to go at get it done myself.

Here are the steps I took to get it done…(as root of course)


cd /usr/local/src
wget ftp://rpmfind.net/linux/redhat-archive/9/en/os/i386/RedHat/RPMS/gcc-3.2.2-5.i386.rpm
wget ftp://rpmfind.net/linux/redhat-archive/9/en/os/i386/RedHat/RPMS/cpp-3.2.2-5.i386.rpm
wget ftp://rpmfind.net/linux/redhat-archive/9/en/os/i386/RedHat/RPMS/glibc-devel-2.3.2-11.9.i386.rpm
wget ftp://rpmfind.net/linux/redhat-archive/7.2/en/os/i386/RedHat/RPMS/kernel-headers-2.4.7-10.i386.rpm
rpm -Uvh kernel-headers-2.4.7-10.i386.rpm
rpm -Uvh glibc-devel-2.3.2-11.9.i386.rpm
rpm -Uvh cpp-3.2.2-5.i386.rpm
rpm -Uvh gcc-3.2.2-5.i386.rpm

I got all of the RPMs from rpmfind.net – these should work on mediatemple since I’m assuming all their boxes use the same cpu/os

The additional rpm’s are dependencies needed by GCC.

-

#Step 1:
#Install Ruby

You need Ruby 1.8.2 or later to run rails. If your OS vendor supplies a packaged version for you, you can use that. Otherwise, you’ll need to download the latest source and compile it yourself.
You check the latest source version at http://ruby-lang.org/en/20020102.html) – as of 12/12/06, you probably want to use Ruby 1.8.5-p2, which fixes a couple denial of service bugs in 1.8.5 and lower.

cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5-p2.tar.gz
tar xvzf ruby-1.8.5-p2.tar.gz
cd ruby-1.8.5-p2
./configure
make
make install

-

#Step 2:
#Install Ruby Gems

Check Latest version and here:
http://rubyforge.org/frs/?group_id=126
http://rubyforge.org/projects/rubygems/

cd /usr/local/src
wget http://rubyforge.org/frs/download.php/5207/rubygems-0.9.0.tgz
tar xvzf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb

-

#Step 3:
#Install Rails

Once Gems are installed its a whirl to install Rails.

$ gem install rails

It will ask you whether it should install some dependencies;
say “y�? to all of them.

-

#Step 4:
#Install FastCGI

There are three pieces of FastCGI software that must be installed on your server to run rails applications: The FastCGI development kit, the mod_fastcgi Apache module, and the Ruby FastCGI bindings. We’ll do the first one now. You can download it from fastcgi.com.

-

Step 4.1:

Install the FCGI Development Kit

Check source version at http://fastcgi.com/dist/

This one is just like the Ruby installation:

cd /usr/local/src
wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz 
tar -xvzf fcgi-2.4.0.tar.gz cd fcgi-2.4.0 ./configure && make && make install

-

More Gotchas

When trying to make mod_fastcgi I ran into this problem:


Makefile:12: /usr/lib/httpd/build/special.mk: No such file or directory
make: *** No rule to make target `/usr/lib/httpd/build/special.mk'.  Stop.

…Fixed it by doing an rpm install of httpd-devel (it didn’t affect any of the apache config files — site continued to work):


$ rpm -Uvh httpd-devel-2.0.46-11.ent.i386.rpm

the mod_fastcgi ‘make’ then complained about needing libtool. fixed that by installing the following:


$ rpm -Uvh automake-1.6.3-5.noarch.rpm
$ rpm -Uvh autoconf-2.57-3.noarch.rpm
$ rpm -Uvh libtool-1.4.3-6.i386.rpm

-

Step 4.2:

mod_fastcgi for Apache 2+

cd /usr/local/src
wget http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar -xvzf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
cp Makefile.AP2 Makefile

Edit Makefile (type: pico Makefile) and change:

top_dir = /usr/local/apache2
to
top_dir = /usr/lib/httpd

Save your changes (cntrl-x in pico) and then make & install:

make 
make install

-

Step 4.3

Install Ruby-FCGI Bindings

gem install fcgi

-

Step 4.4

Install Ruby-MySQL Bindings

gem install mysql

If this fails try:

gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql

-

#Step 5
#Configure Apache

You now need to edit your Apache config file but this can be overwritten by plesk so we need to create a file called fastcgi.conf

-

Step 5.1

fastcgi.conf

fastcgi.conf needs to be created in /etc/httpd/conf.d/

pico /etc/httpd/conf.d/fastcgi.conf

Add these lines:

*

User apache
Group apache
LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiWrapper on FastCgiConfig -idle-timeout 900 FastCgiIpcDir /tmp/fastcgi_ipc/ AddHandler fastcgi-script .fcgi .rb

*

Notes:

  1. If we were editting httpd.conf then the lines “User apache” and “Group apache” need to go before the instruction to include everything in conf.d (the line which reads "conf.d/*") but we cannot (because Plesk overwrites httpd.conf) so putting them in fastcgi.conf is a quick fix. It should not matter that they will esentially appear twice.
  2. On MediaTemple I needed to change the path for the module and used:
    
    LoadModule fastcgi_module /usr/lib/httpd/modules/mod_fastcgi.so
    
  3. I am not sure about the AddHandler line but it doesn’t hurt my installation so I’ve kept it in.
  4. Make sure /tmp/fastcgi_ipc/ is writable and executable by Apache (Apache runs as ‘apache’ – hence the line “User apache” in the conf files).

chown -R apache.apache /tmp/fastcgi_ipc
chmod -R 755 /tmp/fastcgi_ipc

Or, of course, you could just chmod 777 the directory… :)

-

Step 5.2

Restart Apache

Before restarting apache make sure you haven’t done something stupid:

apachectl configtest

If everything is OK then restart:

apachectl -k graceful

Ruby on Rails should now be successfully installed.

-

#Step 6:

#Testing Your installation

Notice I said “should”. I firmly believe in checking things so…

-

Step 6.1

Install Test Application

You can test RoR out by creating a test application. Note, it will probably help if you do not do this as root (as I did). Try doing it as the user for the account you are installing your test application into. Hopefully, if you use the correct user, you won’t need to do Step 6.2.

cd ~USER
rails testapp
cd testapp/
script/generate controller test
cd ../httpdocs
ln -s ../testapp/public rails

Replace USER with the appropriate username ;)

-

Step 6.2

Check Ownership

The owner of the directories and symbolic link created should be USER:psacln so ls -a to find out what they are (ls -a). If they are not correct then:

cd ~USER
chown -R USER.psacln testapp
chmod -R 755 testapp
chown -R USER.psacln httpdocs/rails
chmod -R 755 httpdocs/rails

NB: You may need to set your /testapp/tmp/sessions/ folder permissions and /testapp/log/ files to give your webserver access.

-

Step 6.3

Create Test Pages

If you now naviagte to http://www.yourtestdomain.com/rails/ you should see a “Congratulations” page. However, this is just HTML, to ensure that your installation is working create some test pages:

cd ~USER
cd testapp/app/controllers
pico test_controller.rb

Change the text so that it reads

class TestController < ApplicationController
 def hi
   render :text => 'Hi world'
 end
 def hello
 end
 def index
   render :text => 'Hi! This is the Index.'
 end
end

And now for the cool bit

pico ../views/test/hello.rhtml

*

<html>
  <head>
    <title>Hello World

Hello from Rails!

The current time is <%= Time.now %>

*

Then naviagte to http://www.yourtestdomain.com/rails/test/hi and you should see a page with “Hi world”. Do not go to the other pages yet. You should have noticed that this page took a long time to load. We need to fix that. So:

-

Step 6.4

Increase Speed

You now need to edit testapp/public/.htaccess so that the server implements the Fast CGI version of your test application rather than the slow CGI version.

You will need to remove a hash (#) and add a hash. Change:

# RewriteRule ^(.)$ dispatch.fcgi [QSA,L]
to
RewriteRule ^(.)$ dispatch.fcgi [QSA,L]

Then change:

RewriteRule ^(.)$ dispatch.cgi [QSA,L]
to

  1. RewriteRule ^(.)$ dispatch.cgi [QSA,L]

-

Step 6.5

#Note

On Fedora Core 4 and Plesk 8 the following Warp Speed step does not work. To make it work, do not add the FastCgiServer line and remove “FastCgiWrapper on” line.

Warp Speed

For rails to go into production (and hence maximise it’s speed) you also need to ensure that ‘RAILS_ENV’ is set in fastcgi.conf. So edit fastcgi.conf

pico /etc/httpd/conf.d/fastcgi.conf

so that it now looks like this:

*

User apache
Group apache
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
    FastCgiWrapper on
    FastCgiConfig -idle-timeout 900
    FastCgiIpcDir /tmp/fastcgi_ipc/
    AddHandler fastcgi-script .rb
    FastCgiServer /home/httpd/vhosts/USER/httpdocs/rails/dispatch.fcgi -idle-timeout 120 
-initial-env RAILS_ENV=production -processes 10

*

#NB

The two lines at the end, starting FastCgiServer, should appear on only one line!
This is the only line which has been added.

-

Step 6.5

Restart Apache

apachectl -k graceful

All should be installed! :)

Naviagte to http://www.yourtestdomain.com/rails/test/hello and you should see your page with “Hello from Rails!” and the time appear very quickly!

Further Reading:

HowtoUseSymLinksToGraftRailsOntoYourWebsite
HowToSetTheBaseURLsOfYourRailsApps
http://www.easy-designs.net/articles/WesthostOnRails/

Comments:

If you’re having trouble getting “gem install mysql” to work and getting errors such as

checking for mysql_query() in -lmysqlclient... no

or when you’re trying to use extconf.rb.. for example:

cd /usr/lib/ruby/gems/1.8/gems/mysql-2.7
ruby extconf.rb

and you’re getting errors such as not being able to find mysql.h then you’ll need to install the package mysql-devel.

I had this problem on Fedora Core 2 and it was a result of not having mysql-devel because I had installed only mysql and mysql-server via AtomicRocketTurtle (ART) rpms via yum.


I’ve documented various rails and plesk adventures: setting up rails with lighty with plesk 8 FC4, upgrading to FC4, and setting up a vhost/subdomain config for lighttpd.

If you’re having trouble trying to get your applications to work under just CGI then make sure in your Plesk setup (I’m running 7.5 on Linux) that you have “CGI Support” disabled under Hosting Setup on the domain you’re using, otherwise things won’t work at all.

I ran into various problems with Fedora Core 2 + Apache2 + Plesk .. too much to clog up this wiki though. If you’re running Apache2 you’ll probably want to read this because you won’t want to install FastCGI.

I’ve documented my install process here (using mod_fcgid) http://mademedia.co.uk/wp-content/uploads/2006/04/rubyinstall-fcgid.txt

I must say, it is very cool to see that this page has helped so many people! I didn’t expect that when I put it together as there wasn’t anything like it.

I just used the instructions to install on a machine running Plesk 8 on Centos 4.4.

It went fairly smoothly. The gotchas that have been added helped when it didn’t (mainly the mysql one).

I would appreciate it if anyone could add comments on good and bad points about using other setups with plesk e.g. fcgid or lighttpd (I just use apache and symoblic links e.g. httpdocs → rails/public – so no need for lighttpd).

Kelly

On my server all libs go to /usr/lib64. This will list all files in httpd-devel package so that you know where they are:

rpm -q -l httpd-devel

For ServInt, CentOS 4, and Plesk 8, I had to make sure that CGI support for the domain was on.

zlib problem gotcha: I did not have zlib installed when I built ruby, but it did not complain at that point, but when I was trying to install gem I got error: No such file to load — zlib (LoadError)

I had to get and install zlib from http://www.zlib.net/ and then rebuild and make install ruby from sources.

After that ruby setup.rb for gems went ok.

These instructions were developed on a server with:
Virtuozzo VPS running Red Hat Enterprise 3, Plesk 7.5.4, and Apache 2.0.40.

However, these instructions have been used with other Plesk set-ups (please see comments at the end, and “gotchas” in the instructions for more details):
Fedora Core 4 & Plesk 8
Fedora Core 2 & Apache2 & Plesk
Virtuozzo VPS running CentOS 4.4, Plesk 8.0.1, and Apache 2.0.52.

These instructions are based on the following sources:
http://wiki.rubyonrails.com/rails/pages/HowtoInstallAndRunRubyOnRailsOnCpanel
http://soapboxconfessional.com/articles/2005/05/25/rails-on-plesk
http://wiki.rubyonrails.com/rails/pages/Ruby+and+Rails+on+Red+Hat+Enterprise+Linux

Many Plesk installations are quite minimal as you are not expected to be fooling around with the server much via commandline. So if the Gotchas don’t help you then please pay attention to the error messages and use the logs. Most things which won’t compile will be missing library files and/or -devel packages.

These instructions assume you are running as a superuser.

-

#Step(s) 0:
#MediaTemple

On Media Temple you may need to get the development kit installed and set up the root password. Also the server does not come with pico or Nano (text editors).

In /usr/local/src

wget <a href="http://www.nano-editor.org/dist/v1.2/nano-1.2.5.tar.gz">http://www.nano-editor.org/dist/v1.2/nano-1.2.5.tar.gz</a>
cd nano-1.2.5
./configure 
make
make install

#Check for zlib

This shouldn’t be necessary for most most people so you can skip this step. However, it may be wise to make sure you have zlib installed before you continue. If you do not have zlib then you will get an error message “require__�? when you try to install rails in step 3.

The way I did it was to create a file called phpinfo.php in my httpdocs with the following:

*

<?php

// Show all information, defaults to INFO_ALL
// phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

*

Naviagte to http://www.yourtestdomain.com/phpinfo.php and you should see zlib meantioned somewhere. If not you will need to install it from http://www.gzip.org/zlib/

-

Gotchas

On my mediatemple AS (application server) there wasn’t even GCC installed. I had to go at get it done myself.

Here are the steps I took to get it done…(as root of course)


cd /usr/local/src
wget ftp://rpmfind.net/linux/redhat-archive/9/en/os/i386/RedHat/RPMS/gcc-3.2.2-5.i386.rpm
wget ftp://rpmfind.net/linux/redhat-archive/9/en/os/i386/RedHat/RPMS/cpp-3.2.2-5.i386.rpm
wget ftp://rpmfind.net/linux/redhat-archive/9/en/os/i386/RedHat/RPMS/glibc-devel-2.3.2-11.9.i386.rpm
wget ftp://rpmfind.net/linux/redhat-archive/7.2/en/os/i386/RedHat/RPMS/kernel-headers-2.4.7-10.i386.rpm
rpm -Uvh kernel-headers-2.4.7-10.i386.rpm
rpm -Uvh glibc-devel-2.3.2-11.9.i386.rpm
rpm -Uvh cpp-3.2.2-5.i386.rpm
rpm -Uvh gcc-3.2.2-5.i386.rpm

I got all of the RPMs from rpmfind.net – these should work on mediatemple since I’m assuming all their boxes use the same cpu/os

The additional rpm’s are dependencies needed by GCC.

-

#Step 1:
#Install Ruby

You need Ruby 1.8.2 or later to run rails. If your OS vendor supplies a packaged version for you, you can use that. Otherwise, you’ll need to download the latest source and compile it yourself.
You check the latest source version at http://ruby-lang.org/en/20020102.html) – as of 12/12/06, you probably want to use Ruby 1.8.5-p2, which fixes a couple denial of service bugs in 1.8.5 and lower.

cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5-p2.tar.gz
tar xvzf ruby-1.8.5-p2.tar.gz
cd ruby-1.8.5-p2
./configure
make
make install

-

#Step 2:
#Install Ruby Gems

Check Latest version and here:
http://rubyforge.org/frs/?group_id=126
http://rubyforge.org/projects/rubygems/

cd /usr/local/src
wget http://rubyforge.org/frs/download.php/5207/rubygems-0.9.0.tgz
tar xvzf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb

-

#Step 3:
#Install Rails

Once Gems are installed its a whirl to install Rails.

$ gem install rails

It will ask you whether it should install some dependencies;
say “y�? to all of them.

-

#Step 4:
#Install FastCGI

There are three pieces of FastCGI software that must be installed on your server to run rails applications: The FastCGI development kit, the mod_fastcgi Apache module, and the Ruby FastCGI bindings. We’ll do the first one now. You can download it from fastcgi.com.

-

Step 4.1:

Install the FCGI Development Kit

Check source version at http://fastcgi.com/dist/

This one is just like the Ruby installation:

cd /usr/local/src
wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz 
tar -xvzf fcgi-2.4.0.tar.gz cd fcgi-2.4.0 ./configure && make && make install

-

More Gotchas

When trying to make mod_fastcgi I ran into this problem:


Makefile:12: /usr/lib/httpd/build/special.mk: No such file or directory
make: *** No rule to make target `/usr/lib/httpd/build/special.mk'.  Stop.

…Fixed it by doing an rpm install of httpd-devel (it didn’t affect any of the apache config files — site continued to work):


$ rpm -Uvh httpd-devel-2.0.46-11.ent.i386.rpm

the mod_fastcgi ‘make’ then complained about needing libtool. fixed that by installing the following:


$ rpm -Uvh automake-1.6.3-5.noarch.rpm
$ rpm -Uvh autoconf-2.57-3.noarch.rpm
$ rpm -Uvh libtool-1.4.3-6.i386.rpm

-

Step 4.2:

mod_fastcgi for Apache 2+

cd /usr/local/src
wget http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar -xvzf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
cp Makefile.AP2 Makefile

Edit Makefile (type: pico Makefile) and change:

top_dir = /usr/local/apache2
to
top_dir = /usr/lib/httpd

Save your changes (cntrl-x in pico) and then make & install:

make 
make install

-

Step 4.3

Install Ruby-FCGI Bindings

gem install fcgi

-

Step 4.4

Install Ruby-MySQL Bindings

gem install mysql

If this fails try:

gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql

-

#Step 5
#Configure Apache

You now need to edit your Apache config file but this can be overwritten by plesk so we need to create a file called fastcgi.conf

-

Step 5.1

fastcgi.conf

fastcgi.conf needs to be created in /etc/httpd/conf.d/

pico /etc/httpd/conf.d/fastcgi.conf

Add these lines:

*

User apache
Group apache
LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiWrapper on FastCgiConfig -idle-timeout 900 FastCgiIpcDir /tmp/fastcgi_ipc/ AddHandler fastcgi-script .fcgi .rb

*

Notes:

  1. If we were editting httpd.conf then the lines “User apache” and “Group apache” need to go before the instruction to include everything in conf.d (the line which reads "conf.d/*") but we cannot (because Plesk overwrites httpd.conf) so putting them in fastcgi.conf is a quick fix. It should not matter that they will esentially appear twice.
  2. On MediaTemple I needed to change the path for the module and used:
    
    LoadModule fastcgi_module /usr/lib/httpd/modules/mod_fastcgi.so
    
  3. I am not sure about the AddHandler line but it doesn’t hurt my installation so I’ve kept it in.
  4. Make sure /tmp/fastcgi_ipc/ is writable and executable by Apache (Apache runs as ‘apache’ – hence the line “User apache” in the conf files).

chown -R apache.apache /tmp/fastcgi_ipc
chmod -R 755 /tmp/fastcgi_ipc

Or, of course, you could just chmod 777 the directory… :)

-

Step 5.2

Restart Apache

Before restarting apache make sure you haven’t done something stupid:

apachectl configtest

If everything is OK then restart:

apachectl -k graceful

Ruby on Rails should now be successfully installed.

-

#Step 6:

#Testing Your installation

Notice I said “should”. I firmly believe in checking things so…

-

Step 6.1

Install Test Application

You can test RoR out by creating a test application. Note, it will probably help if you do not do this as root (as I did). Try doing it as the user for the account you are installing your test application into. Hopefully, if you use the correct user, you won’t need to do Step 6.2.

cd ~USER
rails testapp
cd testapp/
script/generate controller test
cd ../httpdocs
ln -s ../testapp/public rails

Replace USER with the appropriate username ;)

-

Step 6.2

Check Ownership

The owner of the directories and symbolic link created should be USER:psacln so ls -a to find out what they are (ls -a). If they are not correct then:

cd ~USER
chown -R USER.psacln testapp
chmod -R 755 testapp
chown -R USER.psacln httpdocs/rails
chmod -R 755 httpdocs/rails

NB: You may need to set your /testapp/tmp/sessions/ folder permissions and /testapp/log/ files to give your webserver access.

-

Step 6.3

Create Test Pages

If you now naviagte to http://www.yourtestdomain.com/rails/ you should see a “Congratulations” page. However, this is just HTML, to ensure that your installation is working create some test pages:

cd ~USER
cd testapp/app/controllers
pico test_controller.rb

Change the text so that it reads

class TestController < ApplicationController
 def hi
   render :text => 'Hi world'
 end
 def hello
 end
 def index
   render :text => 'Hi! This is the Index.'
 end
end

And now for the cool bit

pico ../views/test/hello.rhtml

*

<html>
  <head>
    <title>Hello World

Hello from Rails!

The current time is <%= Time.now %>

*

Then naviagte to http://www.yourtestdomain.com/rails/test/hi and you should see a page with “Hi world”. Do not go to the other pages yet. You should have noticed that this page took a long time to load. We need to fix that. So:

-

Step 6.4

Increase Speed

You now need to edit testapp/public/.htaccess so that the server implements the Fast CGI version of your test application rather than the slow CGI version.

You will need to remove a hash (#) and add a hash. Change:

# RewriteRule ^(.)$ dispatch.fcgi [QSA,L]
to
RewriteRule ^(.)$ dispatch.fcgi [QSA,L]

Then change:

RewriteRule ^(.)$ dispatch.cgi [QSA,L]
to

  1. RewriteRule ^(.)$ dispatch.cgi [QSA,L]

-

Step 6.5

#Note

On Fedora Core 4 and Plesk 8 the following Warp Speed step does not work. To make it work, do not add the FastCgiServer line and remove “FastCgiWrapper on” line.

Warp Speed

For rails to go into production (and hence maximise it’s speed) you also need to ensure that ‘RAILS_ENV’ is set in fastcgi.conf. So edit fastcgi.conf

pico /etc/httpd/conf.d/fastcgi.conf

so that it now looks like this:

*

User apache
Group apache
LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
    FastCgiWrapper on
    FastCgiConfig -idle-timeout 900
    FastCgiIpcDir /tmp/fastcgi_ipc/
    AddHandler fastcgi-script .rb
    FastCgiServer /home/httpd/vhosts/USER/httpdocs/rails/dispatch.fcgi -idle-timeout 120 
-initial-env RAILS_ENV=production -processes 10

*

#NB

The two lines at the end, starting FastCgiServer, should appear on only one line!
This is the only line which has been added.

-

Step 6.5

Restart Apache

apachectl -k graceful

All should be installed! :)

Naviagte to http://www.yourtestdomain.com/rails/test/hello and you should see your page with “Hello from Rails!” and the time appear very quickly!

Further Reading:

HowtoUseSymLinksToGraftRailsOntoYourWebsite
HowToSetTheBaseURLsOfYourRailsApps
http://www.easy-designs.net/articles/WesthostOnRails/

Comments:

If you’re having trouble getting “gem install mysql” to work and getting errors such as

checking for mysql_query() in -lmysqlclient... no

or when you’re trying to use extconf.rb.. for example:

cd /usr/lib/ruby/gems/1.8/gems/mysql-2.7
ruby extconf.rb

and you’re getting errors such as not being able to find mysql.h then you’ll need to install the package mysql-devel.

I had this problem on Fedora Core 2 and it was a result of not having mysql-devel because I had installed only mysql and mysql-server via AtomicRocketTurtle (ART) rpms via yum.


I’ve documented various rails and plesk adventures: setting up rails with lighty with plesk 8 FC4, upgrading to FC4, and setting up a vhost/subdomain config for lighttpd.

If you’re having trouble trying to get your applications to work under just CGI then make sure in your Plesk setup (I’m running 7.5 on Linux) that you have “CGI Support” disabled under Hosting Setup on the domain you’re using, otherwise things won’t work at all.

I ran into various problems with Fedora Core 2 + Apache2 + Plesk .. too much to clog up this wiki though. If you’re running Apache2 you’ll probably want to read this because you won’t want to install FastCGI.

I’ve documented my install process here (using mod_fcgid) http://mademedia.co.uk/wp-content/uploads/2006/04/rubyinstall-fcgid.txt

I must say, it is very cool to see that this page has helped so many people! I didn’t expect that when I put it together as there wasn’t anything like it.

I just used the instructions to install on a machine running Plesk 8 on Centos 4.4.

It went fairly smoothly. The gotchas that have been added helped when it didn’t (mainly the mysql one).

I would appreciate it if anyone could add comments on good and bad points about using other setups with plesk e.g. fcgid or lighttpd (I just use apache and symoblic links e.g. httpdocs → rails/public – so no need for lighttpd).

Kelly

On my server all libs go to /usr/lib64. This will list all files in httpd-devel package so that you know where they are:

rpm -q -l httpd-devel

For ServInt, CentOS 4, and Plesk 8, I had to make sure that CGI support for the domain was on.

zlib problem gotcha: I did not have zlib installed when I built ruby, but it did not complain at that point, but when I was trying to install gem I got error: No such file to load — zlib (LoadError)

I had to get and install zlib from http://www.zlib.net/ and then rebuild and make install ruby from sources.

After that ruby setup.rb for gems went ok.