Skip to content

Deploy maphub in production mode

slhck edited this page Jul 18, 2012 · 2 revisions

This guide explains how to run maphub in production mode with Apache 2. We assume you haven't run maphub in development mode before. If you have already, skip to the part where we configure Apache.

Note: This guide has been tested on Ubuntu Server 10.10 and should be working for any Ubuntu release or similar distribution. Your mileage may vary for other systems, especially regarding Apache setup.

Prerequisites

  • Ruby 1.9.3
  • Ruby Gems 1.8
  • Java VM
  • Apache 2

Rails needs Apache2 to work, so just install apache2 on your distribution and make sure it will run and your server is reachable on port 80 (and optionally 3000 for testing). We will later configure Rails integration with Apache.

Installing maphub

The following instructions were tested with ruby 1.9.3 and gem 1.8. We recommend RVM for controlling your local Ruby environments.

ruby -v
gem -v

We also recommend to create a separate RVM Gemset for the maphub portal:

rvm gemset create maphub
rvm gemset use maphub

Optionally you can set maphub to be the default gemset

rvm use 1.9.3-head@maphub --default

Clone the maphub code on your local machine:

git clone git@github.com:maphub/maphub-portal.git

Update your gem tool with gem update --system and install the bundler gem with gem install bundler. cd to the project folder and run to install all necessary gems for the maphub tool.

bundle install

Now, start the Solr engine.

RAILS_ENV='production' rake sunspot:solr:start

There's no database and data for maphub yet, so we will add some. The seed step is optional if you already have other sample data (see here for more options to add test data).

RAILS_ENV='production' rake db:migrate
RAILS_ENV='production' rake db:seed

Now, we have to precompile our assets so that they're compressed and moved to public/assets:

rake assets:precompile

You're now good to go. We only have to start the server. Remember though that every time you pull changes, you have to recompile the assets. If you switch environments, you'll also have to rm -rf public/assets just to make sure.

Configuring Apache and Passenger

Passenger is needed for Apache2 to serve the Rails project. The following section will work with Ubuntu. Follow the installation instructions for Passenger if you're on RPM-based distributions or would like to explore it yourself.

gem install passenger
passenger-install-apache2-module

The above command will guide you through the installation. It'll probably prompt you to install some libraries. Once you've done that, start the tool again. Finally compiling the Apache extensions might take another few minutes.

You will be prompted to edit your Apache configuration file, which would be /etc/apache2/httpd.conf on Ubuntu. Add something like the following — but notice that you'll have to change the paths here. Just copy whatever the Passenger installation script told you to do.

LoadModule passenger_module /home/maphub/.rvm/gems/ruby-1.9.3-head@maphub/gems/passenger-3.0.13/ext/apache2/mod_passenger.so
PassengerRoot /home/maphub/.rvm/gems/ruby-1.9.3-head@maphub/gems/passenger-3.0.13
PassengerRuby /home/maphub/.rvm/wrappers/ruby-1.9.3-head@maphub/ruby

Now, in httpd.conf, add your virtual host, replacing the ServerName as well as the path to the maphub-portal's public folder:

<VirtualHost *:80>
   ServerName yourserver.example.com
   # !!! Be sure to point DocumentRoot to 'public'!
   DocumentRoot /home/maphub/maphub-portal/public
   <Directory /home/maphub/maphub-portal/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
   </Directory>
</VirtualHost>

Once that's done, restart Apache:

sudo /etc/init.d/apache2 restart

Now, one thing left to be done. Point your browser to the virtual host's URL, e.g. yourserver.example.com.