apache2 + ubuntu edgy + ruby

Discussion in 'Ruby' started by Sam Waller, Dec 8, 2006.

  1. Sam Waller

    Sam Waller Guest

    I'm running Ubuntu edgy linux, apache2, php5, and ruby 1.8.4

    I've been able to get apache2 to run php scripts easily but am having
    problems getting ruby to do so. I've read references to eruby,
    libapache2-mod-ruby, fastcgi etc, etc. So, I'm not sure what I really
    need. I did install Ubuntu's libapache2-mod-ruby and I now see
    /etc/apache2/mods-enabled/ruby.load -> /etc/apache2/mods-available/ruby.load.
    I also found a /usr/lib/apache2/modules/mod_ruby.so.

    I've tried many variations in the site .conf file in
    /etc/apache2/sites-available/www.site.local. What I currently have in
    this file is:

    <VirtualHost *>
    ServerAdmin
    ServerName www.site.local
    ServerAlias site.local

    AddHandler cgi-script .rb

    DirectoryIndex index.php
    DocumentRoot /var/www/site

    # CGI Directory
    ScriptAlias /cgi-bin/ /var/www/site/
    <Location />
    Options +ExecCGI
    </Location>

    # Logfiles
    ErrorLog /var/www/site/logs/error.log
    CustomLog /var/www/site/logs/access.log combined
    </VirtualHost>

    Since php is working here is what I have added to /etc/apache2/apache2.conf:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .html

    I'm only trying to get apache2 to run ruby programs (.rb files) like it
    does .php files. Can someone tell me what is needed to make this work?

    When I try to run a test.rb file I'm getting this in the error.log file:

    [Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] (2)\xd9\x05i\xb7: exec of
    '/var/www/site/test.rb' failed
    [Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] Premature end of script headers: test.rb

    and the browser shows:

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to
    complete your request.

    Please contact the server administrator, and inform them
    of the time the error occurred, and anything you might have done that may have
    caused the error.

    More information about this error may be available in the server error log.

    test.rb just contains this:

    #!/usr/bin/ruby
    print "Content-type: text/html\r\n\r\n"
    print "<html><body>Hello World!</body></html>\r\n"

    thanks,

    Sam
    Sam Waller, Dec 8, 2006
    #1
    1. Advertising

  2. * Sam Waller <> [2006-12-08 12:00]:
    >When I try to run a test.rb file I'm getting this in the error.log file:
    >
    >[Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] (2)\xd9\x05i\xb7: exec of
    >'/var/www/site/test.rb' failed
    >[Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] Premature end of script headers: test.rb


    It might be a problem with suexec. Check suexec.log. You probably have to change the permissions on the script -- suexec doesn't like scripts (or the directories they're in) to be group-writable.
    Grant Hollingworth, Dec 8, 2006
    #2
    1. Advertising

  3. Sam Waller

    Sam Waller Guest

    On Sat, 9 Dec 2006 06:44:27 +0900, Grant Hollingworth <> wrote:

    >* Sam Waller <> [2006-12-08 12:00]:
    >>When I try to run a test.rb file I'm getting this in the error.log file:
    >>
    >>[Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] (2)\xd9\x05i\xb7: exec of
    >>'/var/www/site/test.rb' failed
    >>[Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] Premature end of script headers: test.rb

    >
    >It might be a problem with suexec. Check suexec.log. You probably have to change the permissions on the script -- suexec doesn't like scripts (or the directories they're in) to be group-writable.


    'which ruby' say
    /usr/bin/ruby

    the permissions and ownership of test.rb:
    -rwxr-xr-x 1 www-data www-data 110 2006-12-08 12:37 test.rb*

    the directory that test.rb was in: /var/www/site was owned by root and I changed it to
    www-data:www-data and I get the same error.


    I tried changing test.rb to the following but still get the same error and couldn't find additional
    information:

    require 'net/http'
    http = Net::HTTP.new('localhost', 80)
    resp, page = http.get('/var/www/site', nil )

    I also tried removing the space as mentioned but get the same results.

    I also have run into problems with carriage returns and linefeeds in scripts so I dumped test.rb
    just to be sure:

    00000000 23 21 2f 75 73 72 2f 62 69 6e 2f 72 75 62 79 0d |#!/usr/bin/ruby.|
    00000010 0a 70 72 69 6e 74 20 22 43 6f 6e 74 65 6e 74 2d |.print "Content-|
    00000020 74 79 70 65 3a 74 65 78 74 2f 68 74 6d 6c 5c 72 |type:text/html\r|
    00000030 5c 6e 5c 72 5c 6e 22 0d 0a 70 72 69 6e 74 20 22 |\n\r\n"..print "|
    00000040 3c 68 74 6d 6c 3e 3c 62 6f 64 79 3e 48 65 6c 6c |<html><body>Hell|
    00000050 6f 20 57 6f 72 6c 64 21 3c 2f 62 6f 64 79 3e 3c |o World!</body><|
    00000060 2f 68 74 6d 6c 3e 5c 72 5c 6e 22 0d 0a |/html>\r\n"..|
    0000006d

    Thanks for your help,
    Sam
    Sam Waller, Dec 9, 2006
    #3
  4. Sam Waller

    Sam Waller Guest

    On Sat, 09 Dec 2006 12:15:37 GMT, Steven J Masta <> wrote:

    >Sam Waller wrote:
    >
    ><snip>
    >
    >> When I try to run a test.rb file I'm getting this in the error.log file:
    >>
    >> [Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] (2)\xd9\x05i\xb7: exec of
    >> '/var/www/site/test.rb' failed
    >> [Fri Dec 08 13:52:30 2006] [error] [client 127.0.0.1] Premature end of script headers: test.rb

    >
    >You'll get that if you have DOS style (CRLF) line endings in your
    >script. Convert to Unix (LF) and see if that fixes it.
    >
    >Steve


    That was the problem: I needed to get rid of the carriange returns (0x0d). I used the 'fromdos' in
    Ubuntu's packages. Thanks.
    Sam Waller, Dec 9, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amir  Michail
    Replies:
    3
    Views:
    6,509
    Amir Michail
    Apr 25, 2007
  2. SPE - Stani's Python Editor
    Replies:
    1
    Views:
    452
    SPE - Stani's Python Editor
    Apr 29, 2008
  3. Passiday
    Replies:
    1
    Views:
    273
    Passiday
    Dec 15, 2011
  4. Ruby Tuesday
    Replies:
    1
    Views:
    94
    gabriele renzi
    Feb 24, 2004
  5. Dick Davies

    cant get mod-ruby working on apache2

    Dick Davies, Apr 26, 2004, in forum: Ruby
    Replies:
    3
    Views:
    128
    Dick Davies
    Apr 27, 2004
Loading...

Share This Page