ModRuby compiles, builds, and runs on UNIX-like operating systems (Linux, FreeBSD, Mac OS X). A lot of work has gone into making ModRuby easy to compile and build in general and especially on Debian/Ubuntu.
ModRuby only works with the Apache prefork MPM, which is the traditional
Apache backend. The Debian package will require this
(apache2-mpm-prefork
) as a dependency. Most sites that use
PHP or other frameworks use this backend as well. ModRuby will not
work with the threaded (worker MPM) backend. This is mainly because
the Ruby VM is not reentrant, and mod_ruby
therefore has no
support for reentrancy as well.
If you are using Ubuntu/Debian, you can build binary packages easily. Just do the following:
bash $
apt-get install git build-essential devscripts pbuilder cmakebash $
git clone https://github.com/mikeowens/ModRuby.gitbash $
cd ModRubybash $
sudo /usr/lib/pbuilder/pbuilder-satisfydependsbash $
fakeroot debian/rules cleanbash $
dpkg-build -b
And this will build the complete debian package. The resulting deb file(s) will be put in the above directory. For example, it produces the following on AMD 64:
bash $
ls ../
total 17M
drwxr-xr-x 3 owensmk owensmk 4.0K 2009-07-27 16:27 .
drwxr-xr-x 3 owensmk owensmk 4.0K 2009-07-28 14:35 ..
-rw-r--r-- 1 owensmk owensmk 426K 2009-07-27 16:27 mod-ruby_3.0.0-1_amd64.build
-rw-r--r-- 1 owensmk owensmk 1.9K 2009-07-27 16:27 mod-ruby_3.0.0-1_amd64.changes
-rw-r--r-- 1 owensmk owensmk 207K 2009-07-27 16:26 mod-ruby_3.0.0-1_amd64.deb
-rw-r--r-- 1 owensmk owensmk 1004 2009-07-27 16:27 mod-ruby_3.0.0-1.dsc
-rw-r--r-- 1 owensmk owensmk 16M 2009-07-27 16:25 mod-ruby_3.0.0-1.tar.gz
-rw-r--r-- 1 owensmk owensmk 337K 2009-07-27 16:26 mod-ruby-dev_3.0.0-1_amd64.deb
drwxr-xr-x 15 owensmk owensmk 4.0K 2009-07-28 14:15 mod-ruby
ModRuby requires the following dependencies:
Apache Portable Runtime.
Apache Web Server source code.
Flex.
CMake. Version 2.6 or higher is required.
Installing the prerequisites in FreeBSD is easy. You need to make sure you have FreeBSD ports installed however. That said, do the following as root:
bash $
pkg_add -r wget cmake flex apache2 sqlite3bash $
cd /usr/ports/lang/ruby19 && make && make installbash $
cd /usr/ports/devel/apr1 && make && make install
Then you can fetch the ModRuby source and build it normally, as described in Section 2.4, “Compiling”
On Max OS X you need to make sure the following are installed on your system:
XCode. This is the basic build environment needed to compile and build everything.
Ruby 2.4.0. For now, the build system looks for the Ruby version
installed by Mac Ports (located in /opt
. This can be easily
expanded by modifying the top-level CMakeLists.txt
file to
look in other places for the Ruby executable.
If you have these, then everything should compile normally as described in the next section.
To compile from scratch, you need to get the Apache source. Download and
extract it into apache/lib/src
. On Debian you would do this
as follows (from source root):
bash $
apt-get install apache2-prefork-dev
Now from within the source root, you can build the project:
bash $
cmake .bash $
make
Copy mod_ruby.so
to wherever your Apache modules directory
is. Copy the debian/mod_ruby.load
and
mod_ruby.conf
scripts to your module configuration
directory (or put their contents into your main Apache configuration file). The
copy the lib/core
contents into your Ruby site install
directory. That should do it.
To make development easier, you can run everything from the source distribution without having to install anything. That way, the changes you make as you develop can take affect immediately (sometimes requiring an Apache restart). You just have to symlink things to the right places.
To install from your source directory, use the following symlinks:
bash $
ln -s /{path_to}/mod_ruby/example /etc/apache2/sites-available/bash $
ln -s /{path_to}/mod_ruby/debian/mod_ruby.load /etc/apache2/mods-available/bash $
ln -s /{path_to}/mod_ruby/debian/mod_ruby.conf /etc/apache2/mods-available/bash $
ln -s /{path_to}/mod_ruby/apache/mod_mod_ruby.so.2.0.0 /usr/lib/apache2/modules/mod_mod_ruby.sobash $
ln -s /{path_to}/mod_ruby/lib/core/mod_ruby.rb /usr/lib/ruby/{1.9.x}/bash $
ln -s /{path_to}/mod_ruby/lib/core/mod_ruby /usr/lib/ruby/{1.9.x}/bash $
ln -s /{path_to}/mod_ruby/example /var/www/mod_ruby-examplebash $
mkdir /usr/share/mod_rubybash $
ln -s /{path_to}/mod_ruby/lib/site /usr/share/mod_ruby/bash $
ln -s /{path_to}/mod_ruby/lib/assets /usr/share/mod_ruby/
Now enable everything:
bash $
sudo a2enmod mod_ruby includebash $
sudo a2ensite mod_ruby-examplebash $
sudo apache2ctl restart
To install from your source directory, use the following symlinks:
bash $
ln -s /{path_to}/mod_ruby/config/mod_ruby.conf /usr/local/etc/apache2/Includes/bash $
ln -s /{path_to}/mod_ruby/apache/mod_mod_ruby.so.2.0.0 /usr/local/libexec/apache22/mod_mod_ruby.sobash $
ln -s /{path_to}/mod_ruby/lib/core/mod_ruby.rb /usr/local/lib/ruby/1.9/bash $
ln -s /{path_to}/mod_ruby/lib/core/mod_ruby /usr/lib/ruby/1.9/bash $
mkdir /var/www/bash $
ln -s /{path_to}/mod_ruby/example /var/www/mod_ruby-examplebash $
mkdir /usr/share/mod_rubybash $
ln -s /{path_to}/mod_ruby/lib/site /usr/share/mod_ruby/bash $
ln -s /{path_to}/mod_ruby/lib/assets /usr/share/mod_ruby/
Once the packages are installed, you need to enable
mod_ruby
and the example site as follows:
user@host $
sudo a2enmod mod_rubyuser@host $
sudo a2ensite mod_ruby-example
If you are running a stock Ubuntu Apache install, that’s it! Restart Apache to institute the changes using apache2ctl restart.
If you are not using the default Ubuntu Apache configuration and wish to
configure it manually, you can modify the VHost configuration in
mod_ruby-example.conf
. The following as a minimal
configuration to get the ModRuby module loaded and a simple site running:
LoadModule ruby_module /usr/lib/apache2/modules/mod_ruby.so <IfModule ruby_module> AddHandler ruby-handler .rsp AddHandler ruby-handler .rhtml AddHandler ruby-script-handler .rb AddType text/html .rhtml .rb RubyDefaultHandlerModule 'modruby' RubyDefaultHandlerClass 'ModRuby::Handler' RubyDefaultHandlerMethod 'handle' </IfModule> <VirtualHost *> ServerName modruby.example.org ServerAdmin webmaster@example.org DocumentRoot "/var/www/modruby-example/content" <Directory /> Options Includes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
This tells Apache to load the mod_ruby.so
module, and
associate its handler to files with the suffixes .rb
and
.rhtml
. The AddType
directive defines
associates these extension with text/html
MIME types. You
could rather associate these suffixes with system’s
mime.types
configuration file. In this case, you would
simply modify the appropriate line of that file as follows:
text/html html htm rb rhtml
Be sure to restart Apache to make these changes take effect.
It is important that you use a fully-qualified domain name in your browser
for the example site, otherwise cookies will not work properly. By default, the
Apache configuration file for the example site uses the domain
modruby.example.org
. You need to add an entry to your
/etc/hosts
file as follows:
127.0.0.1 modruby.example.org
Now you can load the example site in your browser by going to http://modruby.example.org.
So that’s it. Everything is set up and working. Let’s move on to the interesting stuff.