CGIの起動

  • 設定ファイルの場所:

/etc/init.d/httpd
Directory "/var/www/html"

http://httpd.apache.org/docs/2.0/ja/howto/cgi.html

    • 設定ファイルの変更 /etc/init.d/httpd

(1)CGIの許可

Options +ExecCGI

(2)rubyの許可
#AddHandler cgi-script .cgi
↓変更
AddHandler cgi-script .cgi .pl

  • 再起動

/etc/init.d/httpd restart

全部必須(特に2行目も)
test1.cgi

#!/usr/bin/ruby
puts "Content-type: text/html\n\n"
puts "helloworld"

#!/usr/bin/rubyの部分は

which ruby

ででてくるもの.

/var/www/cgi-bin/test1.cgi

に配置.http://localhost/cgi/test1.cgi にエーリアスされてる.
実行権限の付与

chmod 705 test1.cgi


http://www.searchman.info/fedoracore4_apply/sev1020.html
とかを参考にしました.

  • フォームから値をもらって表示する.

フォームの作り方は以下を参照
http://www.futomi.com/lecture/form/

test1.rb

#!/usr/bin/ruby
require 'cgi'
cgi=CGI.new

puts "Content-type: text/html\n\n"
puts cgi['main_keyword']
puts cgi['e_mail']

puts "helloworld"

test2.html

<head>
</head>
<body>
<h1>Test CGI ver1 </h1>
<hr>
<form action="/cgi-bin/test1.rb" name="js" method="post">
Keyword: <br>
<input type="text" name="main_keyword" value="test"> <br>
Email: <br>
<input type="text" name="e_mail"> <br>
And: <br>
<input type="text" name="and_key1"> <input type="text" name="and_key2"> <input type="text" name="and_key3"> <input type="text" name="and_key4">
<input type="text" name="and_key4">  <input type="text" name="and_key5">  <input type="text" name="and_key6"> <input type="text" name="and_key7">    <br>
Or: <br>
<input type="text" name="or_key1"> <input type="text" name="or_key2"> <input type="text" name="or_key3"> <input type="text" name="or_key4">
<input type="text" name="or_key4">  <input type="text" name="or_key5">  <input type="text" name="or_key6"> <input type="text" name="or_key7">    <br>
Not:<br>
 <input type="text" name="not_key1"> <input type="text" name="not_key2"> <input type="text" name="not_key3"> <input type="text" name="not_key4">
<input type="text" name="not_key4">  <input type="text" name="not_key5">  <input type="text" name="not_key6"> <input type="text" name="not_key7">    <br>

<input type="submit" name="submit" value="send"> <br>
</form>
</body>
</html>


ログの確認
httpd.confの
ServerRootを確認
/etc/httpd そこにある.

/etc/httpd/logs にあった.

ここから必須でないけど
rubyの更新
http://centos.bungu-do.jp/archives/000294.html
ruby-gems
http://centos.bungu-do.jp/archives/000294.html
http://www.adminweb.jp/apache/log/index1.html

sudo gem install nokogiri
sudo gem install mechanize

  • ruby内のsystemをつかってruby関数を呼ぶときは,

system(ruby test.rb) でなく,system(./testrb)
を使う.権限も調整. ファイル出力は全員に書き込み権限をあたえたフォルダをつくる.


/var/lib/alternatives