NSLU2-Linux
view · edit · print · history

HowTo.DeployRubyUsingLighttpd History

Hide minor edits - Show changes to markup

June 21, 2008, at 04:34 PM by toby --
Changed lines 71-72 from:

</body> </html>

to:

Contents of directory:
<pre>
<%=`ls -la`%>
</pre>
</body>
</html>

June 21, 2008, at 04:33 PM by toby --
Deleted lines 28-29:

\\ rescue Exception\\

Added lines 30-31:

rescue Exception
\\

June 21, 2008, at 04:18 PM by toby --
Deleted lines 30-31:
  
print "Content-Type: text/html\n\n"\\
Added lines 32-33:
  print "Content-Type: text/html\n\n"
\\
Changed lines 49-51 from:
  1. Make this script executable: chmod uag+rx erb.cgi
to:
  1. Make this script executable:
    chmod uag+rx erb.cgi
June 21, 2008, at 04:17 PM by toby --
Changed lines 48-49 from:
  1. Make this script execuatable: chmod uag+rx erb.cgi
to:


# Make this script executable: chmod uag+rx erb.cgi

Added lines 57-58:
  1. Add "index.rhtml" as one of the default documents
    index-file.names = ( "index.rhtml", ...
Deleted line 60:
Added lines 63-74:
  1. Save the /etc/lighttpd.conf file and restart the server
    /etc/init.d/lighttpd restart
  2. Create a test web page in /www/pages/index.rhtml
    <html>
    <body>
    Hello World! The time is now <%=Time.now%>!
    </body>

</html>

  1. Load it in a web browser:
    wget http://localhost/

You can now write your web app in Ruby using Erb templates!

June 21, 2008, at 04:13 PM by toby --
Added lines 49-61:
  1. Make this script execuatable: chmod uag+rx erb.cgi
  2. Change /etc/lighttpd.conf - uncomment the line to load the CGI module
    ...
    server.modules = (
    ...
    "mod_cgi", ...
    )
  3. Add ".rhtml" to the static file exclusions
    static-file.exclude-extensions = ( ".rhtml", ".php", ".pl", ".fcgi" )
  4. Add the cgi handler for .rhtml
    cgi.assign = ( ".rhtml" => "/www/pages/cgi-bin/erb.cgi" )
June 21, 2008, at 04:08 PM by toby --
Changed lines 5-55 from:

@@

  1. !/usr/bin/ruby
  2. erb.cgi
  3. Apache script handler for .rhtml files
  4. based on work by Brian Bugh and Paul McArdle?
  5. see http://dekstop.de/weblog/2006/01/rhtml_on_osx_with_apache_and_erb/
  6. Martin Dittus (martin@dekstop.de), 2006-01-09
  7. last change: 2006-01-11

require 'time' require 'erb'

time = Time.now.httpdate

HEADERS = <<EOF Date: #{ time } Server: #{ ENV['SERVER_SOFTWARE'] } Last-Modified: #{ time } Content-Type: text/html

EOF

begin

  1. print HEADERS + "testing " + ENV.inspect
  2. return if true
  erb = File.open(ENV["SCRIPT_FILENAME"]) { |f| ERB.new(f.read) }
  print HEADERS + erb.result(binding)

rescue Exception

  print "Content-Type: text/html\n\n"

  # error message
  print "<h1>Script Error</h1>"
  print "<pre>#{ $! }</pre>"

  # debug info
  print "<h2>Backtrace</h2>"
  print "<pre>#{$!.backtrace.join("\n")}</pre>"

  print "<h2>Environment</h2>"
  print "<pre>#{ENV.keys.map { |key| key + ' = ' + ENV[key] + "\n"} }</pre>"

  print "<hr>"
  print "<i>#{__FILE__} -- #{time}</i>"

end @@

to:


#!/usr/bin/ruby

# erb.cgi
# Apache script handler for .rhtml files
# based on work by Brian Bugh and Paul McArdle?
# see http://dekstop.de/weblog/2006/01/rhtml_on_osx_with_apache_and_erb/

require 'time'
require 'erb'

time = Time.now.httpdate

HEADERS = <<EOF
Date: #{ time }
Server: #{ ENV['SERVER_SOFTWARE'] }
Last-Modified: #{ time }
Content-Type: text/html

EOF

begin
erb = File.open(ENV["SCRIPT_FILENAME"]) { |f| ERB.new(f.read) }
print HEADERS + erb.result(binding)
\\ rescue Exception

print "Content-Type: text/html\n\n"

# error message
print "<h1>Script Error</h1>"
print "<pre>#{ $! }</pre>"

# debug info
print "<h2>Backtrace</h2>"
print "<pre>#{$!.backtrace.join("\n")}</pre>"

print "<h2>Environment</h2>"
print "<pre>#{ENV.keys.map { |key| key + ' = ' + ENV[key] + "\n"} }</pre>"

print "<hr>"
print "<i>#{__FILE__} -- #{time}</i>"
end

June 21, 2008, at 04:05 PM by toby --
Added lines 1-55:
  1. Install lighttpd with the cgi module
  2. Install ruby
  3. In the document root directory (in my case /www/pages) create a cgi-bin directory
  4. Create the following file in this cgi-bin directory called erb.cgi:

@@

  1. !/usr/bin/ruby
  2. erb.cgi
  3. Apache script handler for .rhtml files
  4. based on work by Brian Bugh and Paul McArdle?
  5. see http://dekstop.de/weblog/2006/01/rhtml_on_osx_with_apache_and_erb/
  6. Martin Dittus (martin@dekstop.de), 2006-01-09
  7. last change: 2006-01-11

require 'time' require 'erb'

time = Time.now.httpdate

HEADERS = <<EOF Date: #{ time } Server: #{ ENV['SERVER_SOFTWARE'] } Last-Modified: #{ time } Content-Type: text/html

EOF

begin

  1. print HEADERS + "testing " + ENV.inspect
  2. return if true
  erb = File.open(ENV["SCRIPT_FILENAME"]) { |f| ERB.new(f.read) }
  print HEADERS + erb.result(binding)

rescue Exception

  print "Content-Type: text/html\n\n"

  # error message
  print "<h1>Script Error</h1>"
  print "<pre>#{ $! }</pre>"

  # debug info
  print "<h2>Backtrace</h2>"
  print "<pre>#{$!.backtrace.join("\n")}</pre>"

  print "<h2>Environment</h2>"
  print "<pre>#{ENV.keys.map { |key| key + ' = ' + ENV[key] + "\n"} }</pre>"

  print "<hr>"
  print "<i>#{__FILE__} -- #{time}</i>"

end @@

view · edit · print · history · Last edited by toby.
Originally by toby.
Page last modified on June 21, 2008, at 04:34 PM