Running with Apache as mod_fcgid

The mod_fcgid module is a high-performance alternative to mod_cgi and handles all requests for programs (such as Ruby) that need to be executed on the server. This recipe may not be a very popular choice due to the fact that many standalone Ruby servers such as Thin, Puma, and Phusion Passenger now exist. However, it may be required, and it's very reliable and relies only on Apache and Ruby executables.

Getting ready

  • Install Redmine as explained in Installing Redmine from a source on Ubuntu to the home directory.
  • Install Apache and mod_fastcgid by typing the following:
    sudo apt-get install apache2 libapache2-mod-fcgid
    

How to do it…

Once the prerequisites are installed, and Redmine is confirmed as working with WEBrick, then navigate to /home/youruser/redmine/public and type the following commands:

cd /home/youruser/redmine/public
mv dispatch.fcgi.example dispatch.fcgi
chmod 755 dispatch.fcgi
mv htaccess.fcgi.example .htaccess

Create a new virtual host for Apache, or edit the default host. We will create a new host called redmine.yoursite.com:

sudo nano /etc/apache2/sites-available/redmine.yoursite.com

Enter the following contents:

<VirtualHost *:80>
        ServerName redmine.yoursite.com
        DocumentRoot /home/youruser/redmine/public
        <Directory /home/youruser/redmine/public >
                Options Indexes ExecCGI FollowSymLinks
                Order allow,deny
                Allow from all
                AllowOverride all
        </Directory>
        ErrorLog /var/log/apache2/yoursite_error.log
        CustomLog /var/log/apache2/yoursite_access.log combined
</VirtualHost>

Enable your new website and restart Apache:

sudo a2ensite redmine.yoursite.com
sudo service apache2 restart

After restarting, your Redmine should be ready and accessible through http://redmine.yoursite.com provided DNS is set properly or at least hosts file for testing purposes.

How it works…

At first, we installed mod_fcgid for Apache, then we prepared dispatch.fcgi; .htaccess, dispatch.fcgi is used by mod_fcgid through Apache and Ruby to run Redmine. htaccess tells Apache what to do with dispatch.fcgid. After this, we created a new virtual server for Apache. This may be done through an Apache management tool, such as Webmin for example, but then the value needs to be entered through an entry form or edited like we did from the command line in this recipe. After creating a virtual server, we enabled it and tested Redmine.

There's more…

If you get an error such as, Rails application failed to start properly, try some of the troubleshooting recipes from Chapter 9, Troubleshooting (the Troubleshooting Apache installations section.)

See also

The official mod_fcgid website is http://httpd.apache.org/mod_fcgid/.

More on Apache administration can be found at https://httpd.apache.org/docs/2.2/vhosts/name-based.html.