How to Setup Apache With FastCGI And Ruby Bindings

转载 2007年09月24日 21:54:00

How to install Apache, Ruby, RubyGems, Rails, and FastCGI? under Linux

  1. Become root and go to a directory to work in
    
    su root
    cd /usr/local/src
  2. Download all of the needed files. These versions may be out of date, so you might want to go find the latest.
    
    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
  3. Install Ruby
    
    tar -zxvf ruby-1.8.5.tar.gz
    cd ruby-1.8.5
    ./configure
    make
    make test
    make install
    cd ..
  4. Install Ruby Gems
    
    tar -zxvf rubygems-0.9.0.tgz
    cd rubygems-0.9.0
    ruby setup.rb
    cd ..
  5. Install Apache (if needed—if you have an existing Apache installation & know what you are doing this step can be skipped)
    
    tar -zxvf httpd-2.2.3.tar.gz
    cd httpd-2.2.3
    ./configure --enable-rewrite --enable-cgi --enable-so
    make
    make install
    cd ..
    
  6. Install FastCGI?
    
    tar -zxvf fcgi-2.4.0.tar.gz 
    cd fcgi-2.4.0
    ./configure
    make
    make install
  7. Install mod_fcgi
    mod_fastcgi is heavily outdated and very hard to install it is better to use mod_fcgid
    
    wget http://fastcgi.coremail.cn/mod_fcgid.1.10.tar.gz
    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
  1. If fcgid is not working for you try installing mod_fastcgi for Apache (note that this assumes you are using Apache-2.x, etc.; if you are using Apache 1.3, DSOs, etc. read the INSTALL file.
  2. Install Rails
    
    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
        :
    
  3. Install the fcgi gem
    
    gem install fcgi
    
    gem install fcgi -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib
    

    If you receive an error which contains “can’t find header files for ruby.”, then please install the ruby-devel package.
  4. Edit your Apache configuration (typically found somewhere like /usr/local/apache2/conf/httpd.conf or /etc/httpd/conf/httpd.conf) and add these lines:
    
    <Directory /var/www/>
        AllowOverride all
    </Directory>
    
    LoadModule fastcgi_module modules/mod_fastcgi.so
    
    AddHandler fastcgi-script .fcgi
    
    <VirtualHost *:80>
        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
    </VirtualHost>
  5. Edit your Apache configuration (with fcgid instead of fastcgi)
    FastCGI is severly outdated, so it is recommended that you use FCGID instead. If you use FCGID two lines in the configuration file will be different:
    
    LoadModule fcgid_module modules/mod_fcgid.so
    # in case of mod_fcgid you may want to add 
    <IfModule mod_fcgid.c>
        AddHandler fcgid-script .fcgi
        IPCCommTimeout 40
        IPCConnectTimeout 10
        DefaultInitEnv RAILS_ENV production
        SocketPath /tmp/fcgidsock
    </IfModule>
    
  6. Start Apache
    
    /usr/local/apache2/bin/apachectl start
  7. Go to http://www.example.com and see the Rails welcome page.
  8. Set up a database for Rails in database.yml (or see HowToUseRailsWithoutADatabase).
  9. Create a simple controller for testing Rails
    
    cd /var/www/rails/testapp/public
    rm index.html
    cd ..
    script/generate controller home index
  10. Go to www.example.com/home/index and see a default view, running with normal cgi.
  11. Enable FastCGI?
    1. Edit /var/www/rails/testapp/public/.htaccess and change dispatch.*cgi* to dispatch.*fcgi*
    2. Edit /var/www/rails/testapp/public/dispatch.fcgi (in rails 0.13.1 this is within the rails installation: lib/fcgi_handler.rb) and change
      require 'fcgi'

      to
      require 'rubygems'
      require_gem 'fcgi'
  12. Go to www.example.com/home/index and see a default view again, but with 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 search 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}<br>/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.


I’ve been bitten by two things with the Apache configuration: I had MultiViews on, and I was redirecting /some/url.html to /some/url because I don’t want file extensions in my URLs. The second rule causes endless redirect looping with standard Rails’ .htaccess, and MultiViews interferes badly with Rails’ caching. So, keep MultiViews off, and be careful with those redirects. —Matijs van Zuijlen


I have yet to get Apache fcgi working Windows XP SP2. I’ve got Apache working with Rails but it’s slow as mud. I’ve downloaded all the software that I can find and put in the http.conf file the recommended Apache configuration but can’t tell if fcgi is working or not.

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

<html>
  <head>
    <title>Ajax Demo</title>
    <%= javascript_include_tag "prototype" %>
  </head>
  <body>
    <h1>What time is it?</h1>
    <div id="time_div">
      I don't have the time, but
      <%= link_to_remote( "click here",

                         :update => "time_div",
                         :url =>{ :action => :say_when }) %>
      and I will look it up.
    </div>
  </body>
</html>

 

I get the page minus the “click here” link????


For anyone trying to get fastcgi working after installing the gem version of the ruby fastcgi lib, I found uninstalling it, then loading the library version and building it, fixed all problems. Download from here http://raa.ruby-lang.org/project/fcgi/ read the README and build and install, and fastcgi starts working.

Jewelry Blog



I’ve got lots of help by reading dev411
article on Installing Typo: MySQL, Apache, lighttpd and FastCGI

Don’t foreget to comment out

AddHandler fast_cgi-script .fcgi

and add

AddHandler fcgid-script .fcgi

to your .htaccess or it wont work.


If you are running on freebsd/mysql and your database.yml is fine but you hit.

Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info

update your ports and install the ruby-mysql port.

no need for mysql gem and all the grief that causes :)



If you get an error installing ruby at make install that looks like

fileutils.rb:1239:in `copy’: unknown file type: ./.ext/. (RuntimeError)

try running make first (so ./configure, then make, then make test, make install)
(http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/237532)


If you get this error on ruby setup.rb when installing gems

/usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:4:in `require’: no such file to load — zlib (LoadError)

make sure zlib and zlib-devel are installed, then follow these instructions:
http://lucaschan.com/weblog/2007/03/22/installing-ruby-on-rails-on-centosredhat-4x/

 

How to Setup Your Own Hotspot with OPENWRT (BackFire) and CoovaChilli

Important note: This solution requires a Hotspot Operator Account at HotSpotSystem.com. You can crea...

Google Merchant How To Setup A Live XML Data Feed With MySql and PHP

Setting up a live data feed for Google Merchant (Google Shopping) can be tricky if you don’t know ho...

How to Create a High Availability Setup with Pacemaker, Corosync and Floating IPs on CentOS 7

How to Create a High Availability Setup with Pacemaker, Corosync and Floating IPs on CentOS 7 Poste...
  • gzhouc
  • gzhouc
  • 2016年11月20日 14:01
  • 468

How to Use Cocoa Bindings and Core Data in a Mac App

How to Use Cocoa Bindings and Core Data in a Mac App Learn how to use Cocoa...
  • yuanya
  • yuanya
  • 2014年05月05日 13:36
  • 1194

How to setup a Mac with Python dev tools

How to setup a Mac with Python dev tools Notes for how to setup a 64-bit Mac with important Pyt...
  • WHACKW
  • WHACKW
  • 2015年04月22日 09:17
  • 827

How to setup FlumeNG with example configuration

1. Check out the source For those that prefer subversion: $ svn checkout https://svn.apache....
  • linhx
  • linhx
  • 2012年06月16日 19:46
  • 1588

How to setup linked servers for SQL Server and Oracle 64 bit client

How to setup linked servers for SQL Server and Oracle 64 bit client ProblemWe have two SQL 2005 64-b...

How to Setup Xen4 and pvops 2.6.32.x on CentOS 5.5

How to Setup Xen4 and pvops 2.6.32.x on CentOS 5.5 2011-04-29 13:17 Setting up Xen4 ha...

How to Install Ruby on Rails on Ubuntu 12.04 LTS (Precise Pangolin) with RVM

转自: https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts...

How To Use MySQL with Your Ruby on Rails Application on Ubuntu 14.04

Introduction Ruby on Rails uses sqlite3 as its default database, which works great in many cases, b...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to Setup Apache With FastCGI And Ruby Bindings
举报原因:
原因补充:

(最多只允许输入30个字)