ruby mod_ruby eruby step1

erubyをやってみた@ centos

1)ソースから ruby-1.8.10をインストール(yumでやんなかったのはgemが使えなかったから)
2)ソースから eruby-1.0.5をインストール (erubyはCでかかれているのだよ)
3)ソースから mod_ruby-1.3.0をインストール

[root@cent5-64b-40 src]# ls -l | grep ruby
drwxr-sr-x  3   1000  1000      4096  9月 29 22:17 eruby-1.0.5
-rw-r--r--  1 root   root      61187 12月 14  2004 eruby-1.0.5.tar.gz
drwxr-sr-x  5   1000  1000      4096  9月 29 22:51 mod_ruby-1.3.0
-rw-r--r--  1 root   root     114246 11月  8  2008 mod_ruby-1.3.0.tar.gz
drwxr-xr-x 19  10347 10347      4096  9月 29 22:13 ruby-1.8.7-p352
-rw-r--r--  1 root   root    4894181  9月 29 22:09 ruby-1.8.7-p352.tar.gz
drwxr-xr-x  7 narumi games      4096  8月 27 09:49 rubygems-1.8.10
-rw-r--r--  1 root   root     249683 10月  4 21:36 rubygems-1.8.10.tgz
[root@cent5-64b-40 src]# 

事前に必要なyumのパッケージは
httpd-devel yum パッケージ(apxsのため)

rubyの場合は
./configure -enable-shared
make
make install

erubyの場合は
./configure --enable-shared --with-charset=UTF-8


エラーが発生したので、

CONFIG["XLDFLAGS"] || "" のように || ""を追加


erubyが生成されたら /var/www/cgi-binにeruby execファイルをコピーする

mod_rubyの場合は、
./configure.rb --with-apxs=/usr/sbin/apxs --with-apx-includes=/usr/include/apr-1
make
make install

make installすると、/usr/lib/httpd/modules とか
/usr/local/lib/ruby/1.8/apacheあたりにいろいろはいる。


これにてインストールは終了。

次はコンフィグ

前半は mod_rubyのためのコンフィグ。
お尻の2行は erubyのためのコンフィグ


[root@cent5-64b-40 conf.d]# ls -l | grep ruby
-rw-r--r-- 1 root root 756  9月 30 07:38 ruby.conf
[root@cent5-64b-40 conf.d]# 
[root@cent5-64b-40 conf.d]# cat ruby.conf 
LoadModule ruby_module modules/mod_ruby.so

<IfModule mod_ruby.c>
RubyRequire apache/ruby-run

# /ruby以下のファイルをRubyスクリプトとして実行する
#<Location /ruby>
# SetHandler ruby-object
# RubyHandler Apache::RubyRun.instance
#</Location>

# *.rbをRubyスクリプトとして実行する
<Files *.rb>
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
</Files>

#Rubyを実行するディレクトリでCGIを実行可能にする
<Location /ruby>
Options +ExecCGI
</Location>
</IfModule> 


#<Location /ruby>
#Options +ExecCGI
#AddType application/x-httpd-eruby .rhtml
#Action application/x-httpd-eruby /cgi-bin/eruby
#</Location>

AddType application/x-httpd-eruby .rhtml
Action application/x-httpd-eruby /cgi-bin/eruby
[root@cent5-64b-40 conf.d]# 


erubyのテストファイルはこんなの

[root@cent5-64b-40 conf.d]# cat /var/www/html/time.rhtml 
<html>
<head>
<title>Japan local time</title>
</head>

<body>

<p><%= "時刻は " + Time.now.to_s %></p>

</body>
</html>
[root@cent5-64b-40 conf.d]# 

ほぼおんなじだけど

[root@cent5-64b-40 ruby]# cat /var/www/html/ruby/test.rhtml 
<html>
<head>
<title>今何時?</title>
</head>
<body>
<%
	puts "ただいまの日時は #{Time.now.strftime('%Y/%m/%d %X')}"
%>
</body>
</html>
[root@cent5-64b-40 ruby]#

つづいて
mod_rubyのテストファイル

[root@cent5-64b-40 ruby]# cat /var/www/html/ruby/index.rb 
require 'cgi'

cgi = CGI.new
print cgi.header("type" => "text/html")

print "hello"

[root@cent5-64b-40 ruby]#