These instructions have been tested twice with a clean minimal install of CentOS 4.3 after a yum update running under VMWare.
Note: I couldn’t make it run with my CentOS 4.3, I was getting this in my Apache error logs:
server /home/myuser/public_html/rubytest/dispatch.fcgi(26580) started
Fri Oct 27 12:07:31 2006 mod_fcgid: process /home/myuser/public_html/rubytest/dispatch.fcgi(26580) exit(communication error), terminated by calling exit(), return code: 114
I tried with mod_fastcgi-2.4.2-3.fc4.i386.rpm and the other instructions in Rail on Fedora and worked fine.
Note: WikiGardening is in process – Brazen… actually I’ve pretty much abandoned this page as it’s too much work when people change things and introduce typos or just plain wrong information. It would also be better IMO if any questions for added to the very end. So if anyone else wants to double check it’s current state and clean things up (including removing my discussion comments, or move them to the end) then knock yourself out :D
Optional: Remove some unnecessary cruft.yum remove stunnel up2date cups gpm system-config-mouse pcmcia-cs isdn4k-utils NetworkManageryum updatechkconfig yum on && service yum startshutdown -r now) to load any updated kernel.yum install httpd-devel httpd apr apr-devel apr-util-devel emacs-common mysql-develyum install mysql-servervi /etc/my.cnfold_passwords=1to thisold_passwords=0Install FastCGI
wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gztar -xzf fcgi-2.4.0.tar.gzcd fcgi-2.4.0./configuremakemake installcd ../Install mod_fcgid
cd ~wget http://fastcgi.coremail.cn/mod_fcgid.1.09.tar.gztar -xzf mod_fcgid.1.09.tar.gzcd mod_fcgid.1.09vi MakefileChange top_dir to:
top_dir = /usr/lib/httpd
Uncomment #INCLUDES and change to
INCLUDES=-I /usr/include/httpd -I /usr/include/apr-0
makemake installcd ../cd /etc/yum.repos.d/wget http://dev.centos.org/centos/4/CentOS-Testing.repoyum --enablerepo=c4-testing install ruby ruby-docs ri ruby-libs ruby-mode ruby-tcltk irb rdoc ruby-develNote: you may need to install ruby-irb instead of irb from the testing repo if version numbers do not match up
Install Ruby Gemswget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgztar -xzf rubygems-0.9.0.tgzcd rubygems-0.9.0ruby setup.rbcd ../gem install rails --include-dependenciesgem install fcgigem install mysql -- --with-mysql-config=/usr/bin/mysql_config
vi /etc/ld.so.confAdd line:
/usr/local/lib
/sbin/ldconfigCreate Test Application – this will get you started on the popular “cookbook” tutorial from OnLamp.
mkdir /var/www/railscd /var/www/rails/rails cookbookSet Permissions on Test Application
chgrp -R apache cookbook/chmod -R g+r cookbook/chmod -R g+w cookbook/log/chmod -R g+w cookbook/tmp/find /var/www/rails/cookbook/ -type d -exec chmod g+x {} \;Configure Apache
vi /etc/httpd/conf.d/fcgid.confInsert the following:
LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so
<IfModule mod_fcgid.c>
SocketPath /tmp/fcgid_sock/
AddHandler fcgid-script .fcgi
</IfModule>vi /etc/httpd/conf.d/hosts.conf(Personally, I put all my custom Apache configuration in this file to keep things organized)Insert the following:
<VirtualHost *:80>
SetEnv RAILS_ENV development
ServerName dnsnameoripaddress
DocumentRoot /var/www/rails/cookbook/public/
ErrorLog /var/www/rails/cookbook/log/apache.log
<Directory /var/www/rails/cookbook/public/>
Options ExecCGI FollowSymLinks
AddHandler fcgid-script .fcgi
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>vi /var/www/rails/cookbook/public/.htaccessChange line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
And change:
AddHandler fastcgi-script .fcgi
to
AddHandler fcgid-script .fcgi
do NOT change the require line as other guides tell you to do.Hello, World!
cd /var/www/rails/cookbook/ruby script/generate controller MyTestvi app/controllers/my_test_controller.rbChange file to read:
class MyTestController < ApplicationController
def index
render :text => "Hello World!"
end
end/sbin/service httpd startNote: There was a typo in this hello world example which I fixed. The : before text was missing.
Note: you’ll need to run system-config-securitylevel-tui and add “www” to open up the firewall (or configure the firewall however you prefer to open tcp port 80).
Access http://dnsnameoripaddress/MyTest, “Hello World” should be displayed.
At this stage Ruby tells me “Recognition failed for MyTest” – yay more digging around looking for fixes!
I believe the URL is incorrect, I got the same error and after a bit of digging it would seem that you get that page for any ‘page not found’ errors if your Ruby server is running in development mode. If you change the url to: http://dnsnameoripaddress/mytest it works. The ONLamp tutorial uses windows, in which the urls are not case sensitive. Even though the app was created with uppercase names, the URL must be lowercase Actually at one point, any of these three URLs would work: MyTest, mytest, or my_test, even on case sensitive OSes. For some reason an update to rails changed this.
I got an error: [error] (13)Permission denied: mod_fcgid: couldn't bind unix domain socket /etc/httpd/logs/fcgidsock/1534.5 and fixed it by executing sudo chmod 555 /etc/httpd/logs/ and going to http://dnsnameoripaddress/my_test
%{color:red}At this point, it.. sort of works.
no route found to match "/MyTest" with {:method=>:get}
I have to browse deeply into my directory structure to even get to the MyTest application.
IE: http://rails.janga.org/janga/public/MyTest – just to get an error to pop in the development.log file.
My presumption is that I’d be able to hit http://rails.janga.org/MyTest/ and see something.%
In order to get /MyTest to work, you have to add a route.
vi config/routes.rb
and add a line in the body:
map.connect 'MyTest/:id', :controller => 'MyTest', :action => 'index'
Appendix A – using PHP to manage the database
yum -y install php-mysql php-mbstring php-gd php-mbsringcd ~wget http://superb-east.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.8.1.tar.gztar -xzf phpMyAdmin-2.8.1.tar.gzcd phpMyAdmin-2.8.1mkdir /var/www/phpmyadminmv * /var/www/phpmyadmin/vi /var/www/phpmyadmin/config.inc.php<?php
/*
* Generated configuration file
* Generated by: phpMyAdmin 2.8.1 setup script by Michal Čihař
* Version: $Id: setup.php,v 1.23.2.8.2.2 2006/05/15 07:57:09 nijel Exp $
* Date: Sun, 11 Jun 2006 17:34:57 GMT
*/
/* Servers configuration */
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'sql.svr.ip.addy';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'mysql-user';
$cfg['Servers'][$i]['password'] = 'mysql-password';
/* End of servers configuration */
?>Be sure to change sql.svr.ip.addy, mysql-user, and mysql-password to match your environment. WARNING this will allow any who can access the web page to manage your MySQL server. Change auth_type to ‘http’ and delete the user and password lines, to be prompted every time you access the phpmyadmin page.vi /etc/httpd/conf.d/hosts.conf<VirtualHost *:80>
Alias /phpmyadmin /var/www/phpmyadmin
...Appendix B – mod_fcgid notes. This is taken verbatim from the mailing list in an email by Peter Gibbons.
mod_fcgid tips (tested on Apache 2.0.55 and mod_fcgid-1.08 on Debian 3.1) Make sure you set IPCCommTimeout to at least 45 to allow enough startup time. Set DefaultMaxClassProcessCount to 2 unless your benchmarks tell you to change. Set IdleTimeout to 3600 or higher since your only have 2 dispatch.fcgi. Set ProcessLifeTime to a multiple of IdleTimeout. Set MaxProcessCount > DefaultMaxClassProcessCount so you can use mod_fcgid for other things than rails. mod_fcgid religiously kills idle or old processes so keep IdleTimeout and ProcessLifeTime to high values. Here is an example 'starter' /etc/apache2/mods-enabled/fcgid.conf <IfModule mod_fcgid.c> AddHandler fcgid-script .fcgi SocketPath /var/lib/apache2/fcgid/sock IdleTimeout 3600 ProcessLifeTime 7200 MaxProcessCount 8 DefaultMaxClassProcessCount 2 IPCConnectTimeout 8 IPCCommTimeout 60 DefaultInitEnv RAILS_ENV production </IfModule> If you have plenty of RAM, then increase DefaultMaxClassProcessCount to about 2*CPU--assume each instance will eat 20-30MB RAM.Appendix C – Setting up the MySQL server
yum -y install mysql-servervi /etc/my.cnfold_passwords=01old_passwords=0ROR has been reported not to work correctly if this is not done.service mysqld start && chkconfig mysqld onsystem-config-security-level-tuiThese instructions have been tested twice with a clean minimal install of CentOS 4.3 after a yum update running under VMWare.
Note: I couldn’t make it run with my CentOS 4.3, I was getting this in my Apache error logs:
server /home/myuser/public_html/rubytest/dispatch.fcgi(26580) started
Fri Oct 27 12:07:31 2006 mod_fcgid: process /home/myuser/public_html/rubytest/dispatch.fcgi(26580) exit(communication error), terminated by calling exit(), return code: 114
I tried with mod_fastcgi-2.4.2-3.fc4.i386.rpm and the other instructions in Rail on Fedora and worked fine.
Note: WikiGardening is in process – Brazen… actually I’ve pretty much abandoned this page as it’s too much work when people change things and introduce typos or just plain wrong information. It would also be better IMO if any questions for added to the very end. So if anyone else wants to double check it’s current state and clean things up (including removing my discussion comments, or move them to the end) then knock yourself out :D
Optional: Remove some unnecessary cruft.yum remove stunnel up2date cups gpm system-config-mouse pcmcia-cs isdn4k-utils NetworkManageryum updatechkconfig yum on && service yum startshutdown -r now) to load any updated kernel.yum install httpd-devel httpd apr apr-devel apr-util-devel emacs-common mysql-develyum install mysql-servervi /etc/my.cnfold_passwords=1to thisold_passwords=0Install FastCGI
wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gztar -xzf fcgi-2.4.0.tar.gzcd fcgi-2.4.0./configuremakemake installcd ../Install mod_fcgid
cd ~wget http://fastcgi.coremail.cn/mod_fcgid.1.09.tar.gztar -xzf mod_fcgid.1.09.tar.gzcd mod_fcgid.1.09vi MakefileChange top_dir to:
top_dir = /usr/lib/httpd
Uncomment #INCLUDES and change to
INCLUDES=-I /usr/include/httpd -I /usr/include/apr-0
makemake installcd ../cd /etc/yum.repos.d/wget http://dev.centos.org/centos/4/CentOS-Testing.repoyum --enablerepo=c4-testing install ruby ruby-docs ri ruby-libs ruby-mode ruby-tcltk irb rdoc ruby-develNote: you may need to install ruby-irb instead of irb from the testing repo if version numbers do not match up
Install Ruby Gemswget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgztar -xzf rubygems-0.9.0.tgzcd rubygems-0.9.0ruby setup.rbcd ../gem install rails --include-dependenciesgem install fcgigem install mysql -- --with-mysql-config=/usr/bin/mysql_config
vi /etc/ld.so.confAdd line:
/usr/local/lib
/sbin/ldconfigCreate Test Application – this will get you started on the popular “cookbook” tutorial from OnLamp.
mkdir /var/www/railscd /var/www/rails/rails cookbookSet Permissions on Test Application
chgrp -R apache cookbook/chmod -R g+r cookbook/chmod -R g+w cookbook/log/chmod -R g+w cookbook/tmp/find /var/www/rails/cookbook/ -type d -exec chmod g+x {} \;Configure Apache
vi /etc/httpd/conf.d/fcgid.confInsert the following:
LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so
<IfModule mod_fcgid.c>
SocketPath /tmp/fcgid_sock/
AddHandler fcgid-script .fcgi
</IfModule>vi /etc/httpd/conf.d/hosts.conf(Personally, I put all my custom Apache configuration in this file to keep things organized)Insert the following:
<VirtualHost *:80>
SetEnv RAILS_ENV development
ServerName dnsnameoripaddress
DocumentRoot /var/www/rails/cookbook/public/
ErrorLog /var/www/rails/cookbook/log/apache.log
<Directory /var/www/rails/cookbook/public/>
Options ExecCGI FollowSymLinks
AddHandler fcgid-script .fcgi
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>vi /var/www/rails/cookbook/public/.htaccessChange line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
And change:
AddHandler fastcgi-script .fcgi
to
AddHandler fcgid-script .fcgi
do NOT change the require line as other guides tell you to do.Hello, World!
cd /var/www/rails/cookbook/ruby script/generate controller MyTestvi app/controllers/my_test_controller.rbChange file to read:
class MyTestController < ApplicationController
def index
render :text => "Hello World!"
end
end/sbin/service httpd startNote: There was a typo in this hello world example which I fixed. The : before text was missing.
Note: you’ll need to run system-config-securitylevel-tui and add “www” to open up the firewall (or configure the firewall however you prefer to open tcp port 80).
Access http://dnsnameoripaddress/MyTest, “Hello World” should be displayed.
At this stage Ruby tells me “Recognition failed for MyTest” – yay more digging around looking for fixes!
I believe the URL is incorrect, I got the same error and after a bit of digging it would seem that you get that page for any ‘page not found’ errors if your Ruby server is running in development mode. If you change the url to: http://dnsnameoripaddress/mytest it works. The ONLamp tutorial uses windows, in which the urls are not case sensitive. Even though the app was created with uppercase names, the URL must be lowercase Actually at one point, any of these three URLs would work: MyTest, mytest, or my_test, even on case sensitive OSes. For some reason an update to rails changed this.
I got an error: [error] (13)Permission denied: mod_fcgid: couldn't bind unix domain socket /etc/httpd/logs/fcgidsock/1534.5 and fixed it by executing sudo chmod 555 /etc/httpd/logs/ and going to http://dnsnameoripaddress/my_test
%{color:red}At this point, it.. sort of works.
no route found to match "/MyTest" with {:method=>:get}
I have to browse deeply into my directory structure to even get to the MyTest application.
IE: http://rails.janga.org/janga/public/MyTest – just to get an error to pop in the development.log file.
My presumption is that I’d be able to hit http://rails.janga.org/MyTest/ and see something.%
In order to get /MyTest to work, you have to add a route.
vi config/routes.rb
and add a line in the body:
map.connect 'MyTest/:id', :controller => 'MyTest', :action => 'index'
Appendix A – using PHP to manage the database
yum -y install php-mysql php-mbstring php-gd php-mbsringcd ~wget http://superb-east.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.8.1.tar.gztar -xzf phpMyAdmin-2.8.1.tar.gzcd phpMyAdmin-2.8.1mkdir /var/www/phpmyadminmv * /var/www/phpmyadmin/vi /var/www/phpmyadmin/config.inc.php<?php
/*
* Generated configuration file
* Generated by: phpMyAdmin 2.8.1 setup script by Michal Čihař
* Version: $Id: setup.php,v 1.23.2.8.2.2 2006/05/15 07:57:09 nijel Exp $
* Date: Sun, 11 Jun 2006 17:34:57 GMT
*/
/* Servers configuration */
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = 'sql.svr.ip.addy';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'mysql-user';
$cfg['Servers'][$i]['password'] = 'mysql-password';
/* End of servers configuration */
?>Be sure to change sql.svr.ip.addy, mysql-user, and mysql-password to match your environment. WARNING this will allow any who can access the web page to manage your MySQL server. Change auth_type to ‘http’ and delete the user and password lines, to be prompted every time you access the phpmyadmin page.vi /etc/httpd/conf.d/hosts.conf<VirtualHost *:80>
Alias /phpmyadmin /var/www/phpmyadmin
...Appendix B – mod_fcgid notes. This is taken verbatim from the mailing list in an email by Peter Gibbons.
mod_fcgid tips (tested on Apache 2.0.55 and mod_fcgid-1.08 on Debian 3.1) Make sure you set IPCCommTimeout to at least 45 to allow enough startup time. Set DefaultMaxClassProcessCount to 2 unless your benchmarks tell you to change. Set IdleTimeout to 3600 or higher since your only have 2 dispatch.fcgi. Set ProcessLifeTime to a multiple of IdleTimeout. Set MaxProcessCount > DefaultMaxClassProcessCount so you can use mod_fcgid for other things than rails. mod_fcgid religiously kills idle or old processes so keep IdleTimeout and ProcessLifeTime to high values. Here is an example 'starter' /etc/apache2/mods-enabled/fcgid.conf <IfModule mod_fcgid.c> AddHandler fcgid-script .fcgi SocketPath /var/lib/apache2/fcgid/sock IdleTimeout 3600 ProcessLifeTime 7200 MaxProcessCount 8 DefaultMaxClassProcessCount 2 IPCConnectTimeout 8 IPCCommTimeout 60 DefaultInitEnv RAILS_ENV production </IfModule> If you have plenty of RAM, then increase DefaultMaxClassProcessCount to about 2*CPU--assume each instance will eat 20-30MB RAM.Appendix C – Setting up the MySQL server
yum -y install mysql-servervi /etc/my.cnfold_passwords=01old_passwords=0ROR has been reported not to work correctly if this is not done.service mysqld start && chkconfig mysqld onsystem-config-security-level-tui