Tag Archives: apache

Running Multiple SequenceServers on Apache2 and Ruby 1.9

What I would like to do is run multiple instances of SequenceServer under different sub-directories on one domain, e.g. http://richardslab.exeter.ac.uk/blastocladiella and http://richardslab.exeter.ac.uk/hyphochytrium but running from one source code directory and one central location for blast databases (although the FASTAs should be in different sub-directories).

This is how I managed it. It’s similar to the way I have set up multiple copies of mediawiki. It’s a little involved, but it seems to work and there may well be other ways – which I would be interested to hear about – and so I can’t guarantee this is the correct, sanest or safest way! So YMMV. However, there are a few challenges to get through first.

Ruby 1.9.* has had a few security updates and in so doing they have removed “.” (the current directory) from load PATH. There’s lots of talk about it on the internet (e.g. here) with various solutions to get it running. It took a bit of figuring out for SequenceServer which would not run directly from github for me, but I think I have cracked it for the latest version (as of 2014-03-31 – 0.8.7?) if you are running it through Apache with Phusion Passenger. Incidentally – and this may be testament to my lack of knowledge of (and desire to know about) Ruby but it won’t run from the command line unless we make a different set of changes. But I suppose you can always install the gem rather than github for that scenario… Unless some one else can help out on this front…

The reason I am running from git source is that I’m not sure where the ruby gem files get installed or what ruby gems does with them and so this way I can be in control of exactly what files I am going to change below…

1) Install SequenceServer from github

First lets put SequenceServer somewhere safe.

cd /usr/share/

Then clone the source from github;

sudo git clone https://github.com/yannickwurm/sequenceserver.git

You’ll notice you cannot run ./bin/sequenceserver without it throwing an error. We will fix that shortly. You may want to at this point run

sudo bundle install && sudo gem update

in order to make sure any ruby gem dependencies that are needed are installed and updated.

You will also need to make sure you have Phusion Passenger installed for Apache.

gem install passenger


Don’t worry about adding the second part to your Apache config, we’ll do that below… BUT you do need to add the first bit!!!

a2enmod passenger

2) Changes to the Sequence Server Source Code

Follow the changes highlighted (bold) in each file below; substitute ‘nano’ for your favourite awesome text editor.

sudo nano config.ru

require ‘rubygems’
require ‘bundler/setup’
#require ‘sequenceserver’
require File.expand_path(File.join(File.dirname(__FILE__), ‘lib/sequenceserver.rb’))

run SequenceServer::App

We will be coming back to this file later…

sudo nano lib/sequenceserver.rb

require_relative ‘./sequenceserver/helpers’
require_relative ‘./sequenceserver/blast’
require_relative ‘./sequenceserver/sequencehelpers’
require_relative ‘./sequenceserver/sinatralikeloggerformatter’
require_relative ‘./sequenceserver/customisation’
require_relative ‘./sequenceserver/version’

sudo nano lib/sequenceserver/helpers.rb

require_relative ‘../sequenceserver/database’

3) The ‘tricky’ Part!

First make a directory for your the first instance of SequenceServer you want to run. In this example I have called my directory blast_genome_n; where n = 1…n etc. You might like to make it something more specific to your needs.

cd /etc/
sudo mkidr blast_genome_n
cd blast_genome_n/

Now we are going to make symlinks to our source code repository in /usr/share/sequenceserver – Note, that we want to get the files (*) from the directory, not the directory itself. We shall be copying them to our current location ‘.’

sudo ln -s /usr/share/sequenceserver/* .

Next comes a bit that you don’t want to mess up. We are going to be removing two of the symlinks and replacing them with copies of a static file. This is because they both contain information that will be specific to each of your instances…

sudo rm config.ru
sudo cp /usr/share/sequenceserver/config.ru .

sudo rm example.config.yml
sudo cp /usr/share/sequenceserver/exampl.config.yml .

You now need to edit each file accordingly.

sudo nano config.ru
We edited this file previously, but we need to update it with the proper location of our configuration file (e.g. this is where you specify the blast database locations etc). So, add this bold line;

SequenceServer::App.config_file = ‘/etc/blast_genome_n/config.yml’
run SequenceServer::App

sudo mv example.config.yml config.yml
sudo nano config.yml

For example;

database: /your/specific/blast/databases/

4) Update Apache httpd.conf

sudo nano /etc/apache2/httpd.conf

Add the section below to the <VirtualHost *:80> section in the config file;

RackBaseURI /blast_genome_n
<Directory /var/www/blast_genome_n>
Options -MultiViews

5) Add a symlink Directory to your Apache Directory

sudo ln -s /etc/blast_genome_n/public blast_genome_n

Make sure it is to the “public” directory! Incidentally, you can also change files in the public directory to ‘static’ files and make individual changes to each server portal, e.g. web page colours…

5) Repeat

Repeat Steps 3-5 for any other separate genome blast portals you wish to create

6) Restart Apache

sudo service apache2 restart

And you’re done! It should now work! 🙂


I run WordPress on the same server in the document root and have mod_rewrite enabled to give nicer URLs, however this will interfere with the sequence retrieval of SequenceServer. So, if you are in the same situation (doesn’t have to be WP, it could be Joomla or any situation where mod_rewrite is interfering) you need to add a few lines to the .htaccess file in the root folder

sudo nano .htaccess
It will look something like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

You need to add a line to make it look like this:

RewriteEngine On

RewriteRule ^blast_genome_n/ – [L]

RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Note how it occurs after turning mod_rewrite on but BEFORE wordpress rewrites are carried out!


For some reason the above “solution” for .htaccess had stopped working. The below now seems to work…

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ – [L]

# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(blastocladiella|deepsea|paramecium|hyphochytrium|frogliver) [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress