Ruby on Apache with mod_ruby

I really want to run some ruby ​​code on an Apache server. I have installed libapache2-mod-rubyand libapache-ruby1.8(full list installed here ). What should I do now to run it ( here )?

+5
source share
2 answers

mod-ruby is not the preferred way to enter the ruby ​​community.

The easiest way to run it to install a passenger (bug) and configure apache to use it.

It’s really easy to do,

You can read the official tutorial here: http://www.modrails.com/install.html

+2
source

quick howto, mod_ruby. , Ubuntu 12.04, :

mod_ruby apache:

sudo apt-get install libapache2-mod-ruby

mod_ruby /var/www, apache, .. /etc/apache2/sites-enabled/000-default

+ExecCGI Options , Ruby:

<Directory /var/www/>
    Options Indexes +ExecCGI

    # Ruby with mod_ruby
    RubyRequire apache/ruby-run
    <Files *.rb>
      SetHandler ruby-object
      RubyHandler Apache::RubyRun.instance
      AddType text/html rb
    </Files>
</Directory>

, , , mime/content script. AddType text/html rb.

, script /var/www, . , /var/www/test.rb:

#!/usr/bin/ruby

puts "Hello World!<br><pre>"

ENV.each { |k,v|
  puts "#{k}=#{v}"
}

puts "</pre>"

:

chmod a+x /var/www/test.rb

:

Hello World!
HTTP_HOST=10.0.1.3
HTTP_CONNECTION=keep-alive
HTTP_CACHE_CONTROL=max-age=0
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
HTTP_ACCEPT_ENCODING=gzip,deflate,sdch
HTTP_ACCEPT_LANGUAGE=en-US,en;q=0.8
HTTP_COOKIE=__test=1;
PATH=/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin
SERVER_SIGNATURE=
Apache/2.2.22 (Ubuntu) Server at 10.0.1.3 Port 80

SERVER_SOFTWARE=Apache/2.2.22 (Ubuntu)
SERVER_NAME=10.0.1.3
SERVER_ADDR=10.0.1.3
SERVER_PORT=80
REMOTE_ADDR=10.0.1.3
DOCUMENT_ROOT=/var/www
SERVER_ADMIN=webmaster@localhost
SCRIPT_FILENAME=/var/www/test.rb
REMOTE_PORT=38188
SERVER_PROTOCOL=HTTP/1.1
REQUEST_METHOD=GET
REQUEST_URI=/test.rb
SCRIPT_NAME=/test.rb
MOD_RUBY=mod_ruby/1.2.6
GATEWAY_INTERFACE=CGI-Ruby/1.1

Apache mod_ruby Ruby CGI ( Ruby ), mod_ruby 8 PHP.

+3

All Articles