I want to use Ruby in Apache through CGI. I have the following in my configuration file:
DocumentRoot /home/ceriak/ruby
<Directory /home/ceriak/ruby>
Options +ExecCGI
AddHandler cgi-script .rb
</Directory>
test.rb
is a testfile placed under /home/ceriak/ruby/
, #!/usr/bin/ruby
included on the first line and given executable permissions. Still, when I visit localhost/test.rb
I get a download window and can obtain the source code.
Interestingly, when I place the same script under /usr/lib/cgi-bin/
and call localhost/cgi-bin/test.rb
it works as supposed.
(Apache2 on Ubuntu 9.10.)
Any idea?
Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client. The example shown is from your default httpd. conf configuration file, if you installed Apache in the default location.
Enable CGI Module in Apache To enable CGI in your Apache server. you need to Load module file mod_cgi.so or mod_cgid.so in your Apache configuration file. The CentOS, Red Hat, Fedora and other rpm based distributions edit /etc/httpd/conf. modules.
There are three ways to execute CGI programs: Specify a directory containing CGI programs in the ScriptAlias directive. Specify the cgi-script handler in the file extension by using the AddHandler directive. Specify the cgi-script handler in the SetHandler directive.
Few things to check:
chmod +x /path/to/file
If you did all that, it should work fine. I have this as my test.rb file:
#!/usr/bin/env ruby
puts <<EOS
Content-type: text/html
<html><body>hi</body></html>
EOS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With