Multiple Rails Applications on 1 Account
Posted by Miraenda Mon, 12 Jun 2006 21:28:00 GMT
For Rails, I spent awhile trying to figure out how to have multiple applications on one account. Many sites mentioned using multiple domains or only having one application per account. Some even spent time revealing tricks in httpd.conf or lighttpd.conf to handle multiple applications. Really, though, there's no big magic to running multiple Rails applications on one account. You simply need to setup the applications separate from each other, then symlink them to different locations in public_html. Below, I will go over two methods I discerned for handling this setup.
A. My first application setup:
- I have an application Typo that is symlinked to my typo folder for my domain http://rubyasylum.com/:
Application location - /home/rubyasyl/typo
Symlink code - cd /home/rubyasyl/public_html && ln -s ../typo/public typo - I have an entry in /usr/local/apache/conf/httpd.conf that has the typo folder as my base folder for my domain:
<VirtualHost 209.200.229.207> ServerAlias rubyasylum.com ServerAdmin webmaster@rubyasylum.com DocumentRoot /home/rubyasyl/public_html/typo BytesLog domlogs/rubyasylum.com-bytes_log ServerName www.rubyasylum.com ServerAlias rubytower.com www.rubytower.com User rubyasyl Group rubyasyl CustomLog /usr/local/apache/domlogs/rubyasylum.com combined ScriptAlias /cgi-bin/ /home/rubyasyl/public_html/typo/cgi-bin/ </VirtualHost>
The changed lines are 4 and 12 for /home/rubyasyl/public_html to /home/rubyasyl/public_html/typo.
B. My second application setup (the subdomain route):
- For these how-tos, I wanted to setup Hieraki Wiki as a demo, so I created the hieraki folder:
Application location - /home/rubyasyl/hieraki - Since I didn't want to have the wiki conflict with my primary application (Typo) and because my domain starts at /home/rubyasyl/public_html/typo, I didn't want to have to put the second application's folder into that location, so I picked the subdomain method to setup the second application. I did this first by creating in cPanel the subdomain wiki.rubyasylum.com in the "Subdomains" area.
- After creating the subdomain, I then went into cPanel's "File Manager" and deleted the subdomain folder called wiki inside the public_html folder.
- Terminating the folder ensures 2 points for the subdomain:
a) The DNS entries still exist
b) The httpd.conf entries still exist - I then symlink the second application to the wiki folder, which recreates that folder:
cd /home/rubyasyl/public_html && ln -s ../hieraki/public wiki
C. The alternate way of doing it (the folder route):
- If you do not have your httpd.conf entry redirecting to a folder within public_html like I do or you aren't a fan of subdomains, you can simply use the folder route instead for the second application:
cd /home/rubyasyl/public_html && ln -s ../secondapp/public foldername - This would have your second application called secondapp linked to a folder called foldername within public_html. As for all my examples, replace my rubyasyl username with your actual cPanel username.
- You will also likely have to add the following line to the .htaccess file at /home/user/public_html/foldername:
RewriteBase /foldername - Put that code above the first RewriteRule line
In the end, think of Rails applications like any others you handle. If you have a blog in your main public_html folder, and you wanted to run a forum on that account as well, you would have to install the forum either in a subdomain or a folder within the account. Rails is the same except you start with the application outside of public_html (at /home/user/appname) and then symlink the public folder within the application (at /home/user/appname/public) to a folder within public_html (/home/user/public_html/foldername). The folder inside public_html, however, cannot already exist for the symlink to setup properly. You can follow my Symlink Cron Tips if you do not have shell access to create these types of symlinks for Rails.
I hope the above is helpful for setting up multiple applications on one account. Please let me know via comments below if you have any questions.
