apache2 + ubuntu edgy + ruby


S

Sam Waller

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 (e-mail address removed)
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, (e-mail address removed) 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
 
Ad

Advertisements

G

Grant Hollingworth

* Sam Waller said:
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.
 
S

Sam Waller

* Sam Waller said:
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
 
Ad

Advertisements

S

Sam Waller

Sam Waller wrote:

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top