Inspired by this weekend’s adventures installing Ruby on Rails w/FastCGI on a Fedora Core 1 system running Ensim 4.03. This makes it seem so easy, but it took a day of troubleshooting to work through this stuff. Hopefully this will help someone else who’s trying to make Ruby on Rails play nice on an Ensim box.
Download and install the latest version of Ruby:
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.2.tar.gz tar vxzf ruby-1.8.2.tar.gz cd ruby-1.8.2 ./configure make make install
Download and install the latest version of RubyGems:
wget http://rubyforge.org/frs/download.php/3463/rubygems-0.8.8.tgz tar vxzf rubygems-0.8.8.tgz cd rubygems-0.8.8 ruby setup.rb
Ruby and RubyGems should be installed now, so let’s install Rails:
gem update gem install rails
FastCGI seems to be installed on the system, but Apache hasn’t been setup to use it. Add the following line at the bottom of the LoadModule section of /etc/httpd/conf/httpd.conf:
LoadModule fastcgi_module modules/mod_fastcgi.so
Now we need to add the FastCGI handler, so add this line right below the AddHandler line for CGI.
AddHandler fastcgi-script .fcgi .fcg .fpl
That’s all that needs to be done with Apache, so we need to restart it now:
service httpd restart
FastCGI should technically be working now, but for some reason Ruby FCGI is borked. Now we need to reinstall the Ruby FCGI gem, but it will fail because of a missing fcgiapp.h file. We need to install the FastCGI Developers Kit to get this file:
wget http://www.fastcgi.com/dist/fcgi.tar.gz cd fcgi-2.4.0 ./configure make make install
Now we can install the Ruby fcgi gem:
gem install fcgi -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib
Now we can create a Rails application on one of the spare websites. We’ll blow away the default html directory and replace it with a symlink to the new Rails application’s public directory:
cd /home/virtual/myfaketestsite.com/var/www rm -rf html/ rails myapp ln -s myapp/public html
We need to change the owner of the myapp files to be the same as the others in this site:
chown -R admin99.admin99 myapp
Point a browser at http://www.myfakewebsite.com and we should be getting the Rails congratulations page. That page needs to go, if we are going to get any further:
mv html/index.html html/index.html.bak
Refreshing the browser should show a Rails Routing Error. Excellent, so we know the dispatch.cgi page is working. Now lets switch to FastCGI. Edit the .htaccess file and change /dispatch.cgi to /dispatch.fcgi. If we refresh the browser now we should get a Rails Routing Error again.
This server has been upgraded to MySQL 4.1, and the default Ruby mysql driver won’t connect because it’s running in old_password compatibility mode (otherwise Ensim can’t connect). In order to fix it we need to reinstall the mysql-ruby client:
wget http://www.tmtm.org/en/mysql/ruby/mysql-ruby-2.5.tar.gz tar vxzf mysql-ruby-2.5.tar.gz cd mysql-ruby-2.5 ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config
Test the connectivity before compiling:
ruby -I. ./test.rb localhost root mypassword
No errors, so install mysql-ruby:
make install



This looks like you are installing it in the root of the server as root. I would like to install all this in the Chroot of the website that i have under ensim.
So when i try to install Rubygems i get the following errors:
[root@host3 rubygems-0.8.8]# gem update
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’: No such file to load — zlib (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/package.rb:9
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/builder.rb:1
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:62:in `manage_gems’
from /usr/local/bin/gem:4
[root@host3 rubygems-0.8.8]# gem install rails
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’: No such file to load — zlib (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/package.rb:9
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/builder.rb:1
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require__’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in `require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:62:in `manage_gems’
from /usr/local/bin/gem:4
Are these normal.
just noticed that the erros start happening when i run the ruby setup.rb
[root@host3 rubygems-0.8.8]# ruby setup.rb
—> bin
lib
—> lib/rubygems
bin
lib
—> lib/rubygems
bin
mkdir -p /usr/local/bin/
install gemwhich /usr/local/bin/
install gem /usr/local/bin/
install gem_server /usr/local/bin/
install generate_yaml_index.rb /usr/local/bin/
install update_rubygems /usr/local/bin/
lib
mkdir -p /usr/local/lib/ruby/site_ruby/1.8/
install ubygems.rb /usr/local/lib/ruby/site_ruby/1.8/
install rubygems.rb /usr/local/lib/ruby/site_ruby/1.8/
install gemconfigure.rb /usr/local/lib/ruby/site_ruby/1.8/
—> lib/rubygems
mkdir -p /usr/local/lib/ruby/site_ruby/1.8/rubygems
install specification.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install builder.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install command.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install config_file.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install custom_require.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install doc_manager.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install format.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install cmd_manager.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install gem_runner.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install installer.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install loadpath_manager.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install old_format.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install open-uri.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install package.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install remote_installer.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install rubygems_version.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install source_index.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install deployment.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install timer.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install user_interaction.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install validator.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install version.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install dependency_list.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
install gem_commands.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
Yes, I was installing as the system root. Off the top head I’m not sure what’s causing your errors, but I may try to install Rails into one of the chrooted accounts and see if I run into the same thing.
I installed as system root and i got same errors, be sure to enable development enviroment for the install to work under chroot.
for some reason i had to install zlib in get rid off these errors. But it is already installed so that is very strange
I found that page looking for the same problem as Tahir. Perhaps you have the same problem, I have instaled zlib .rpm, but there is another .rpm named zlib- -devel-* for development,
Hope it helps.
You definifely need the zlib-devel-* libraries to run gems.
Using Ensim 3.5 and am getting this error:
Symbolic link not allowed: /home/virtual/site2/fst/var/www/html/
How should the directory options be configured to allow the symlink from html to myapp?
Please note that you probably forgot “–” in step 8 when installing the fcgi gem. The command you stated above yields a syntax error.
gem install fcgi — –with-fcgi-include=/usr/local/include
works fine.
[...] This web page and this other one helped a bit, especially in figuring out how to get around the missing fcgiapp.h error message. [...]
I am having a problem with connecting to the database. I can connect through mysql (in the shell) with the appropriate user. My phpMyAdmin works fine. But my rails application fails:
No database specified. Missing argument: database
Trace:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb:34:in `mysql_connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/query_cache.rb:52:in `send’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/query_cache.rb:52:in `connection=’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:108:in `retrieve_connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:239:in `connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:461:in `count_by_sql’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:454:in `count’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/pagination.rb:154:in `count_collection_for_pagination’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/pagination.rb:171:in `paginator_and_collection_for’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/pagination.rb:111:in `paginate’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:756:in `send’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:756:in `perform_action_without_filters’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `measure’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/rescue.rb:80:in `perform_action’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:356:in `send’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/base.rb:356:in `process’
/usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/dispatcher.rb:32:in `dispatch’
/home/john/public_html/client_net/public/dispatch.cgi:10
Here is my correct .yml file:
development:
adapter: mysql
database:john_client_net
host: localhost
username: client_net
password: rubyonrails
I tried updating the mysql-ruby library to 2.6.3 figuring it might be the ole OLD_PASSWORD function problem (running MySQL 4.1.10), but no dice. Any one got any ideas? any place I can look to specifically find the problem?
I have a question (since I followed your last step of updating the mysql-ruby library)… does the –with-mysql-config=/usr/bin/mysql_conf option tell it to look for the configuration there? or to put it’s own configuration there??? (Because if it tells to look there, which I doubt, since it is not a plaintext file, that might be why it doesn’t connect)
I’ll be checking back.. please email me if your respond so I don’t miss it…
mysql_config is the executable mysql configuration tool. Are you getting any errors when running “ruby extconf.rb –with-mysql-config=/usr/bin/mysql_config”?
hey
i have installed everything, without any errors.
the only error i get is inside the fastcgi.crash.log file when try to execute dispatch.fcgi.
the error is:
[22/Nov/2005:14:25:53 :: 20815] Dispatcher failed to catch: undefined method `is_cgi?’ for FCGI:Class (NoMethodError)/usr/lib/site_ruby/1.8/fcgi.rb:593:in `each_cgi’
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/fcgi_handler.rb:52:in `process!’
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/fcgi_handler.rb:22:in `process!’
/home/virtual/site1/fst/var/www/html/public/dispatch.fcgi:24
almost killed by this error
[22/Nov/2005:14:25:53 :: 20815] Dispatcher failed to catch: undefined method `is_cgi?’ for FCGI:Class (NoMethodError)
/usr/lib/site_ruby/1.8/fcgi.rb:593:in `each_cgi’
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/fcgi_handler.rb:52:in `process!’
/usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/fcgi_handler.rb:22:in `process!’
/home/virtual/site1/fst/var/www/html/public/dispatch.fcgi:24
killed by this error
i read in a few places that this is cause by a bad installation of the fcgi gem, and i should try to install it manually. well, if i install it manually, dispatch.fcgi throws out a 500 error. :)
when try to executein the browser, the browser thinks about it for a minute and then throws out a Rails failed message.
running:
ensim 4.0.4 on fedora (i think core 3), apache 2, ruby 1.8.3
please please….i’ve been trying to solve this for two days now…
thanks :)
It seems to me that its more likely caused by a bad install of fcgi rather than the fcgi rubygem. Are you sure that fcgi compiled and installed correctly? Were there any errors when running configure or make?
everything seems to be going flawless when installing fcgi-2.4.0.
i did it again now, and here are the last parts of ./config & make.
configure: creating ./config.statusconfig.status: creating Makefile
config.status: creating cgi-fcgi/Makefile
config.status: creating include/Makefile
config.status: creating libfcgi/Makefile
config.status: creating examples/Makefile
config.status: creating fcgi_config.h
config.status: fcgi_config.h is unchanged
————-
creating echo-cppmake[2]: Leaving directory `/usr/local/src/fcgi-2.4.0/examples’
Making all in include
make[2]: Entering directory `/usr/local/src/fcgi-2.4.0/include’
make[2]: Nothing to be done for `all’.
make[2]: Leaving directory `/usr/local/src/fcgi-2.4.0/include’
make[2]: Entering directory `/usr/local/src/fcgi-2.4.0′
make[2]: Leaving directory `/usr/local/src/fcgi-2.4.0′
make[1]: Leaving directory `/usr/local/src/fcgi-2.4.0′
make install says that:
Libraries have been installed in:/usr/local/lib
i find these files under /usr/local/include:
fastcgi.h fcgiapp.h fcgi_config.h fcgimisc.h fcgio.h fcgios.h fcgi_stdio.hand these ones under /usr/local/lib:
libfcgi.a libfcgi.la libfcgi.so libfcgi.so.0 libfcgi.so.0.0.0libfcgi++.a libfcgi++.la libfcgi++.so libfcgi++.so.0 libfcgi++.so.0.0.0
when doing the gem instal fcgi…. it says:
checking for fcgiapp.h... yeschecking for FCGX_Accept() in -lfcgi... yes
creating Makefile
how can i tell if fcgi was installed properly or not?
thanks…:)
in this article: http://wiki.rubyonrails.com/rails/pages/RailsOnFedora
they say to do:
NB:FastCGI installs to /usr/local/lib, so if it isn’t there already you will need to add /usr/local/lib to /etc/ld.so.conf and run:
$ ldconfig -v
doing this causes dispatch.fcgi to produce a 500 error, although it says:
/usr/local/lib:libfcgi++.so.0 -> libfcgi++.so.0.0.0
libfcgi.so.0 -> libfcgi.so.0.0.0
i think that fastcgi is working now… doing the
ldconfig -vthing i think was what i missed.now i get these messages in fastcgi.crash.log:
[22/Nov/2005:19:49:52 :: 26136] starting[22/Nov/2005:19:49:52 :: 26136] terminated gracefully
but this is showing up in server.log:
[Tue Nov 22 19:49:27 2005] [error] [client 127.0.0.1] FastCGI: incomplete headers (35 bytes) received from server “/home/virtual/site1/fst/var/www/html/public/dispatch.fcgi”dispatch.cgi is working fine, so i don’t think it’s a mysql problem, or my script error.
any ideas or directions i should investigate?
thanks…
I also had the rdoc/rdoc problem in FC4 while installing rails with gem
gem install rails
Attempting local installation of ‘rails’
Local gem file not found: rails*.gem
Attempting remote installation of ‘rails’
Install required dependency rake? [Yn] y
Install required dependency activesupport? [Yn] y
Install required dependency activerecord? [Yn] y
Install required dependency actionpack? [Yn] y
Install required dependency actionmailer? [Yn] y
Install required dependency actionwebservice? [Yn] y
Successfully installed rails-0.14.3
Successfully installed rake-0.6.2
Successfully installed activesupport-1.2.3
Successfully installed activerecord-1.13.0
Successfully installed actionpack-1.11.0
Successfully installed actionmailer-1.1.3
Successfully installed actionwebservice-0.9.3
/usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__’: No such file to load — rdoc/rdoc (LoadError)
from /usr/lib/site_ruby/1.8/rubygems/custom_require.rb:21:in `require’
from /usr/lib/site_ruby/1.8/rubygems/doc_manager.rb:43:in `generate_rdoc’
from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:215:in `execute’
from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:214:in `each’
from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:214:in `execute’
from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:153:in `each’
from /usr/lib/site_ruby/1.8/rubygems/gem_commands.rb:153:in `execute’
from /usr/lib/site_ruby/1.8/rubygems/command.rb:49:in `invoke’
from /usr/lib/site_ruby/1.8/rubygems/cmd_manager.rb:94:in `process_args’ from /usr/lib/site_ruby/1.8/rubygems/cmd_manager.rb:67:in `run’
from /usr/lib/site_ruby/1.8/rubygems/gem_runner.rb:13:in `run’
from /usr/bin/gem:17
i did a
sudo yum install irb ri
and reinstalled gem and rails. It went fine. I think in some of the distros (debian/Fedora)m you shouldnot install Ruby from tha package. Download latest version and install.
What a great installation record!
Thanks a lot!
I’ve gone through these instructions on a Red Hat/Ensim Pro box and everything looks to have installed correctly, but I’m getting a 500 error page when I switch to despatch.fcgi and I don’t thing that FastCGI is working properly. Don’t really know where to start looking for the problem … any help appreciated.