How to install Apache, Ruby, RubyGems, Rails, and FastCGI? under Linux
su root
cd /usr/local/src
wget http://xyz.csail.mit.edu/ruby/ruby-1.8.5.tar.gz
wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
wget http://mirrors.ccs.neu.edu/Apache/dist/httpd/httpd-2.2.3.tar.gz
tar -zxvf ruby-1.8.5.tar.gz
cd ruby-1.8.5
./configure
make
make test
make install
cd ..
tar -zxvf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb
cd ..
tar -zxvf httpd-2.2.3.tar.gz
cd httpd-2.2.3
./configure --enable-rewrite --enable-cgi --enable-so
make
make install
cd ..
tar -zxvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
make install
//fastcgi.coremail.cn/mod_fcgid.1.10.tar.gz
wget http:
tar -zxvf mod_fcgid.1.10.tar.gz
cd mod_fcgid.1.10
# in Makefile set top_dir to the top path of you apache i.e. /usr/local/apache2
make
make install
cd ..
tar -zxvf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
cp Makefile.AP2 Makefile
make
make install
gem install 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
:
gem install fcgi
gem install fcgi -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib
/usr/local/apache2/conf/httpd.conf
or /etc/httpd/conf/httpd.conf
) and add these lines:
AllowOverride all
LoadModule fastcgi_module modules/mod_fastcgi.so
AddHandler fastcgi-script .fcgi
ServerAdmin webmaster@example.com
DocumentRoot /var/www/rails/testapp/public
ServerName www.example.com
ErrorLog /var/log/httpd/testapp-error_log
CustomLog /var/log/httpd/testapp-access_log common
Options Indexes ExecCGI FollowSymLinks
RewriteEngine On
LoadModule fcgid_module modules/mod_fcgid.so
# in case of mod_fcgid you may want to add
AddHandler fcgid-script .fcgi
IPCCommTimeout 40
IPCConnectTimeout 10
DefaultInitEnv RAILS_ENV production
SocketPath /tmp/fcgidsock
/usr/local/apache2/bin/apachectl start
cd /var/www/rails/testapp/public
rm index.html
cd ..
script/generate controller home index
/var/www/rails/testapp/public/.htaccess
and change dispatch.*cgi*
to dispatch.*fcgi*
/var/www/rails/testapp/public/dispatch.fcgi
(in rails 0.13.1 this is within the rails installation: lib/fcgi_handler.rb
) and changerequire 'fcgi'
require 'rubygems'
require_gem 'fcgi'
Troubleshooting Suggestions
Make sure that you delete any ruby session files in your /tmp directory before switching to dispatch.fcgi. If you tested with cgi, there might be some with different permission that what apache (fastcgi) can read and will cause issue.
If you want to see if fastcgi is working with ruby, try pasting the following into test.fcgi (in your rails/public dir). You will need to make sure the file has 755 permissions (chmod 755 test.fcgi).
#!/usr/local/bin/ruby
require 'cgi'
require 'rubygems'
require_gem 'fcgi'
FCGI.each_cgi do |cgi|
content = ''
env = []
cgi.env_table.each do |k,v|
env << [k,v]
end
env.sort!
env.each do |k,v|
content << %Q(#{k} => #{v}
\n)
end
cgi.out{content}
end
Permissions
Make sure that (when using Apache) your www or apache user has write access to your rails/tmp and rails/log directory.
If not you will get many 500 errors!
The above test was working but I didn´t get the dispatcher running under apache2 (self built) until i changed the dependencies of rails-0.14.1/lib/fcgi_handler.rb to:
require 'cgi'
require 'rubygems'
require_gem 'fcgi'
require 'logger'
require 'dispatcher'
require 'rbconfig'
class RailsFCGIHandler
...
I don´t know why this is like this (why the dependencies in the dispatcher should be wrong) but it helped.
Does anyone have a simple step by step recipe to get Apache (v2) on Windows XP Prof running fcgi? I found a test page for Rails but it doesn’t render the link