This is an Apache on Linux web server. This will be useful for setting up php based programs and Ruby on Rails. MySQL will be on a separate server.


First thing, go through DinkelServerBase to get a basic setup. You will want to put /var/www on a separate hard drive (or virtual hard drive) to ease future storage expansion of the web server data folder. Also, any time now, you can use Webmin to open up TCP port 80 on the firewall.


sudo apt-get update && sudo apt-get -y install php5-mysql php5-mcrypt php5-gd

This will also grab apache and the php5 module as decencies. The mysql is needed to allow php5 to work with the MySQL server. The gd is a dependency for almost every php application. The mcrypt is needed for php apps that use secure authentication.

Some PHP configuration:

sudo nano /etc/php5/apache2/php.ini

Change memory_limit = 8M to equal 16M or greater (I use 32M). The post_max_size and upload_max_filesize directives are set to the size of the largest attachments you wish to be able to upload. I set these to 48M and 24M, respectively. This allows multiple file uploads, not to exceed 48 MB, with individual files not exceeding 24 MB.

sudo a2enmod rewrite

This enables the rewrite module, which is needed for Ruby on Rails (RoR) and many web applications.

sudo apt-get -y install ruby irb libapache2-mod-fcgid ruby1.8-dev libfcgi-dev g++ libmysqlclient15-dev

These are definitely needed for Ruby on Rails.

Install Ruby Gems

tar –xzf rubygems-0.9.2.tgz
cd rubygems-0.9.2/
sudo ruby setup.rb
cd ..
rm –rdf rubygems-0.9.2*

You can find the latest version of gems at

sudo gem install rails --include-dependencies

This will install the Rails web framework for Ruby, and it will not prompt you to install for every single dependency. You can ignore the rdoc complaints.

sudo gem install fcgi

This lets rails use fcgi which is much much faster than regular cgi.

sudo gem install mysql

This is what gives you the “Native MySQL bindings” (or “C MySQL bindings”) for Ruby, which has better performance and support for more MySQL features. Be sure to chose the latest “ruby” option when the gem install prompts you.

This should not be necessary, since you should have just installed the latest version of Gems, but you can update Gems with

sudo gem update –system

and update the packages installed by Gems with

sudo gem update

Some Notes: I am not installing ri, libtcltk-ruby, rdoc, and others that some guides tell you to, because these are unnecessary on a webserver. If you need or want any of these tools, they should be installed on a separate development workstation, however you can still do all your RoR development on this webserver (though not suggested) with the tools I have installed. Also, I would not have installed irb, but some RoR functions need it.

Create a RoR test application

Right now, the Apache web server, PHP web scripting language, and RoR web framework are installed and ready to go. The rest of this guide is a tutorial on setting up a sample RoR application which will allow a test of the framework and also give you an idea of the Rails configuration and Apache configuration needed.

sudo mkdir /var/www/rails

This is where all your Rails apps can go.

cd /var/www/rails/
sudo rails cookbook

This sets up the folder structure and files needed for every RoR app. The “rails cookbook” requires root privileges, but this could probably be done as a user if you give users write access to the rails directory with a default mode of 700.

sudo chgrp -R www-data cookbook/ && sudo chmod -R g+r cookbook/ && sudo chmod -R g+w cookbook/log/ && sudo chmod -R g+w cookbook/tmp/ && sudo find /var/www/rails/cookbook/ -type d -exec chmod g+x {} \;

This makes sure Apache has permissions to what it needs and ONLY to what it needs.

Now we do some Apache site setup.

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default.original
sudo nano /etc/apache2/sites-available/default

Change the virtual host section to look like this (WARNING, I need to revise this, but it should work):

<VirtualHost *>
  SetEnv RAILS_ENV development
  ServerName dnsnameoripaddress
  DocumentRoot /var/www/rails/cookbook/public/
  ErrorLog /var/www/rails/cookbook/log/apache.log
  <Directory /var/www/rails/cookbook/public/>
    Options ExecCGI FollowSymLinks
    AddHandler fcgid-script .fcgi
    AllowOverride all
    Order allow,deny
    Allow from all

sudo /etc/init.d/apache2 reload

So apache gets the configuration changes.

Now we do some Rails application setup.

sudo nano /var/www/rails/cookbook/public/.htaccess

Change this line:

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

to this:

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

And change this line:

AddHandler fastcgi-script .fcgi

to this:

AddHandler fcgid-script .fcgi

Do NOT change the ‘require’ line as other guides tell you to do.

Now, let’s do some actual Ruby programming

cd /var/www/rails/cookbook/
sudo ruby script/generate controller MyTest
sudo nano app/controllers/my_test_controller.rb

Change this file to read:

class MyTestController < ApplicationController
  def index
    render_text “Hello World!”

Now, from a workstation, browse to http://dnsnameoripaddress/my_test and see your application in action. You can also go to http://dnsnameoripaddress/ to see a default Rails test page.

Next Steps

You are probably going to want a dynamic, database-driven website, so create a new virtual machine and follow the DinkelVersus/MySQLServer guide.

Appendix A: Mod_fcgid Notes

This is taken verbatim from the mailing list in an email by a ‘Peter Gibbons.’ I’m posting this here for your information. It may be worth doing some tweaking once the webserver Rails apps are under heavy use and performance changes can be measured.

mod_fcgid tips (tested on Apache 2.0.55 and mod_fcgid-1.08 on Debian 3.1)

Make sure you set IPCCommTimeout to at least 45 to allow enough startup 
Set DefaultMaxClassProcessCount to 2 unless your benchmarks tell you to 
Set IdleTimeout to 3600 or higher since your only have 2 dispatch.fcgi.
Set ProcessLifeTime to a multiple of IdleTimeout.
Set MaxProcessCount > DefaultMaxClassProcessCount so you can use 
mod_fcgid for other things than rails.

mod_fcgid religiously kills idle or old processes so keep IdleTimeout 
and ProcessLifeTime to high values.

Here is an example 'starter' /etc/apache2/mods-enabled/fcgid.conf

<IfModule mod_fcgid.c>
  AddHandler fcgid-script .fcgi
  SocketPath /var/lib/apache2/fcgid/sock
  IdleTimeout 3600
  ProcessLifeTime 7200
  MaxProcessCount 8
  DefaultMaxClassProcessCount 2
  IPCConnectTimeout 8
  IPCCommTimeout 60
  DefaultInitEnv RAILS_ENV production

If you have plenty of RAM, then increase DefaultMaxClassProcessCount to 
about 2*CPU--assume each instance will eat 20-30MB RAM.

DinkelVersus/ApacheServer (last edited 2009-04-29 22:56:17 by fooka)