There are several ways to host multiple rails apps on one server; if they are small and there is no conflict between their name spaces you might consider merging them into one "super app"--but for anything larger than toy apps, this is simply asking for trouble, 

h2. Deployment in separate folders for each app on one Apache server

Suppose you'd rather have various Rails apps running on your machine in different folders, with URLs like:

<code><pre>
http://www.myhost.org/appOne/...
http://www.myhost.org/appTwo/...
</pre></code>

This is very easy if you are using [[Apache]] & [[mod_rewrite]].  

# Put a symlink to each application's directory in your document root (e.g., "<code>ln -s /opt/rails/appOne /var/www/html/appOne</code>" and so forth for each application) 
# In each application's <code>.../appName/public/.htaccess</code> file, add the line "<code>RewriteBase /appName</code>" right after the "<code>RewriteEngine On</code>" line.
# In your main <code>httpd.conf</code> file do something like this:<code><pre>
<VirtualHost *>
    ServerName www.myhost.org
    DocumentRoot /var/www/html/
    RewriteEngine On

    RewriteCond %{REQUEST_URI} !^/appOne/public
    RewriteRule ^/appOne(/.*)?$   /appOne/public$1
    <Directory /var/www/html/appOne/public/>
        Options ExecCGI FollowSymLinks
        AllowOverride all
        Allow from all
        Order allow,deny
        </Directory>

    RewriteCond %{REQUEST_URI} !^/appTwo/public
    RewriteRule ^/appTwo(/.*)?$   /appTwo/public$1 
    <Directory /var/www/html/appTwo/public/>
        Options ExecCGI FollowSymLinks
        AllowOverride all
        Allow from all
        Order allow,deny
        </Directory>

    </VirtualHost>

</pre></code>

Note that this differs from the normal in three regards: 
** first, the document root is "normal" (not specific to rails), 
** and secondly there are multiple <code><Directory></code> blocks (one for each rails application), 
** and finally there is a rewrite rule preceding each <code><Directory></code> block to route traffic for that application.

As requests come in, they are rewriiten based on the appName and then handled normally.

h3. Even Simpler Method

# Follow the first step from above (i.e. create symlinks to the public folders of each of the rail applications)
# Then in the main <code>httpd.conf</code>, do this:
<code><pre>
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Users/bob/Sites/
    RewriteEngine On

    <Directory /Users/bob/Sites/>
        Options FollowSymLinks
        AllowOverride all
        Allow from all
        Order allow,deny
    </Directory>

</VirtualHost>
</pre></code>

This is using Rails version 0.12.1, Apache 2.0, and OSX 10.4

category: Howto
