Debian 10 Buster
Sponsored Link

Apache2 : Use Ruby Scripts2019/08/01

 
Enable CGI and Use Ruby Scripts on Apache2.
[1] Install Ruby.
root@www:~#
apt -y install ruby
[2] Enable CGI module.
root@www:~#
a2enmod cgid

Enabling module cgid.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@www:~#
systemctl restart apache2

[3] After enabeling CGI, CGI scripts are allowed to execute under [/usr/lib/cgi-bin] directory by default. Therefore, for example, if a Ruby script [index.cgi] is put under the directory, it's possible to access to the URL [http://(Apache2 Server)/cgi-bin/index.cgi] from Clients.
# create a test script

root@www:~#
cat > /usr/lib/cgi-bin/test_script <<'EOF'
#!/usr/bin/ruby
print "Content-type: text/html\n\n"
print "Hello CGI\n"
EOF
root@www:~#
chmod 705 /usr/lib/cgi-bin/test_script
# try to access

root@www:~#
curl http://localhost/cgi-bin/test_script

Hello CGI
[4] If you'd like to allow CGI in other directories except default, configure like follows.
For example, allow in [/var/www/html/cgi-enabled].
root@www:~#
vi /etc/apache2/conf-available/cgi-enabled.conf
# create new

# processes [.cgi] and [.rb] as CGI scripts

<Directory "/var/www/html/cgi-enabled">
    Options +ExecCGI
    AddHandler cgi-script .cgi .rb
</Directory>

root@www:~#
mkdir /var/www/html/cgi-enabled

root@www:~#
a2enconf cgi-enabled

Enabling conf cgi-enabled.
To activate the new configuration, you need to run:
  service apache2 reload
root@www:~#
systemctl restart apache2

[5] Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
root@www:~#
vi /var/www/html/cgi-enabled/index.rb
#!/usr/bin/ruby

print "Content-type: text/html\n\n"
print "<html>\n<body>\n"
print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n"
print "Ruby Script Test Page"
print "\n</div>\n"
print "</body>\n</html>\n" 

root@www:~#
chmod 705 /var/www/html/cgi-enabled/index.rb

Matched Content