Installation/Webserver Setup

From Pentabarf

Jump to: navigation, search

There are a lot of different options you have concerning the webserver setup for Pentabarf.

The recommended setup is to use Apache with Mongrel or Nginx with Mongrel as this will give you the best performance.

In all cases, you should always use HTTPS. If you do not, your passwords and your data will be transmitted in clear text.


Contents

Apache 2 with Mongrel

You need Apache 2 with mod_proxy_balancer for this to work.

Apache Modules

The modules you need are:

  • mod_proxy
  • mod_proxy_http
  • mod_proxy_balancer

GEM Modules

You need both mongrel and mongrel_cluster.

Apache Configuration

  <Proxy balancer://pentabarf>
    BalancerMember http://127.0.0.1:8001
    BalancerMember http://127.0.0.1:8002
    BalancerMember http://127.0.0.1:8003

    Order allow,deny
    Allow from all
  </Proxy>

  RewriteEngine On
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
  RewriteRule ^/(.*)$ balancer://pentabarf%{REQUEST_URI} [P,QSA,L]

Running Mongrel

Move to the rails directory of the checkout and enter the following command:

 $ mongrel_rails cluster::configure -e production -p 8001 -N 3 -a 127.0.0.1
 Writing configuration file to config/mongrel_cluster.yml.

That creates your configuration file.  Now start mongrel:

 $ mongrel_rails cluster::start
 starting port 8001
 starting port 8002
 starting port 8003

At boot time, you'll need to issue the cluster::start command. This can be done any way you want. We like daemontools.

SSL

If you are using SSL on your Apache server, you need to make Mongrel aware of this fact. Do this by setting the X-Forwarded-Proto and the Host header, like so:

  <Proxy balancer://pentabarf>
    BalancerMember http://127.0.0.1:8001
    BalancerMember http://127.0.0.1:8002
    BalancerMember http://127.0.0.1:8003
    RequestHeader set X-Forwarded-Proto 'https'
    RequestHeader set Host foo.com
  </Proxy>

This will ensure that any generated links will use the right URL.

Apache with FastCGI

1. Configure your Apache for mod_fcgi. You can find detailed instructions at the FastCGI page in the Rails wiki.

2. Add the following line to your httpd.conf

FastCgiConfig -pass-header Authorization

3. Copy the file dispatch.fcgi.template to dispatch.fcgi in the pentabarf/public directory of your checkout.

4. If you have no symbolic link in the path the webserver takes to reach your public directory you can skip this step otherwise adjust the third line of the dispatch.fcgi file to reflect your setup:

Change the following line:

 require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)

to

 require "/path/to/your/pentabarf/checkout/pentabarf/config/environment"

Apache with mod_ruby

If you want to run Pentabarf with Apache you have to copy the file rails/public/htaccess.template to rails/public/.htaccess. You have to change the RewriteBase to the base path of your installation as seen by a browser.

If you want to use Apache with CGI or mod_ruby you need to recompile your Apache with the flag SECURITY_HOLE_PASS_AUTHORIZATION because Apache does not pass the HTTP-Authentication data to the ruby script. Alternatively you can pass Authentication information via a mod_rewrite hack. Something along the lines of

 RewriteEngine On
 RewriteRule /(.*) - [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},PT]

ensures the authentication information is passed in an environment variable called "X-HTTP_AUTHORIZATION". Pentabarf picks that up. See [1] and [2] for further enlightenment.

In some (or most) cases you may need to delete the ",PT" - at the end of the shown RewriteRule.

The performance of mod_ruby is quite good compared to Webrick or CGI but Fast-CGI seems to be a bit faster.

1. Configure your Apache for mod_ruby. You can find detailed instructions at the mod_ruby Page of the Rails-Wiki

2. Copy the file dispatch.rb.template to dispatch.rb in the rails/public directory of your checkout.

3. If you have no symbolic link in the path the webserver takes to reach your public directory you can skip this step. Adjust the third line of the dispatch.rb file to reflect your setup:

Change the following line:

 require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)

to

 require "/path/to/your/pentabarf/checkout/pentabarf/public/config/environment"

Apache 2 with mod_ruby on Debian-systems with apt-packages

Pentabarf needs Rails and Gem for properly working. This rises some problems if your system is a Debian and you want to Rails and Gem via apt.

additional packages needed

There are two additional packages you need to install (they are not installed by default):

  • libyaml-ruby
  • libzlib-ruby

Paths of the Rails libraries are missing

Debian seems to not find the needed paths of Rails by default. In this case, you have to include these paths in your config/boot.rb and config/environment.rb somewhere top of require 'initializer' (change the /usr/share/ - part to your needs):

$LOAD_PATH.push "/usr/share/rails/actionmailer/lib"
$LOAD_PATH.push "/usr/share/rails/actionpack/lib"
$LOAD_PATH.push "/usr/share/rails/actionwebservice/lib"
$LOAD_PATH.push "/usr/share/rails/activerecord/lib"
$LOAD_PATH.push "/usr/share/rails/activesupport/lib"
$LOAD_PATH.push "/usr/share/rails/railties/lib"

Problems with ADDITIONAL_LOAD_PATHS

There will be also an issue with the Additional Load Paths. The data stored in ADDITIONAL_LOAD_PATHS are also stored in $LOAD_PATH (only if you use mod_ruby). So simply include the following line to boot.rb and environment.rb (below the $LOAD_PATH - lines):

ADDITIONAL_LOAD_PATHS = []

SecurityError

The mod_ruby needs to lower the security-level of Ruby to use Rails properly. By default, Ruby runs with security-level 1. It's not the best way, but you have to lower this level to 0. You can do this in the base-level of your httpd.conf - (outsite of any <VirtualHost> tag):

RubySafeLevel 0

<VirtualHost foo.bar.no:443>
...

<IfModule mod_ruby.c>
  RubyRequire apache/ruby-run
  <Files *.rb>
      SetHandler ruby-object
      RubyHandler Apache::RubyRun.instance
  </Files>
</IfModule>

...
</VirtualHost>

Remember to graceful restart your Apache.

Your installation of Pentabarf should now be up and running.

Webrick-Setup

For Webrick no further adjustments are needed change to the pentabarf directory of your checkout and type

 script/server

to start the Webserver. Webrick is listening on port 2342 now. If you are running pentabarf on your local machine it should be here

Personal tools