These steps don't take subversion or capistrano into account. Most of the sites I deploy use these, but they are either on a server that doesn't support Apache 2.2, which means they require a much different setup process that I don't care to document, since I'm hoping to never set up another rails site under those conditions. Or they are on Ubuntu, and therefore I'm using deprec. These steps are for sites that allow me to use Apache 2.2, but I'm not keeping under version control (e.g., blogs running third-party apps, like this one!).
I'm also not going into installation of ruby, gem, or apache. That's pretty much different for every operating system. Hit up the google for that info if you need it. On to the steps!
- Upload everything to the server
- ssh to the server, create the database, and run the migrations.
Install rails, mongrel, and mongrel_cluster:
$ sudo gem install rails -y $ sudo gem install mongrel -y $ sudo gem install mongrel_cluster -yCreate mongrel config, and start the processes:
$ cd /path/to/app # Assuming you want 3 mongrel processes, starting on port 8000: $ mongrel_rails cluster::configure -e production -p 8000 -N 3 -c . -a 127.0.0.1 $ mongrel_rails cluster::startAdd the virtualhost to apache:
<VirtualHost *:80> ServerName mysite.com DocumentRoot /path/to/app/public <Directory /path/to/app/public> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> # Configure mongrel_cluster <Proxy balancer://mysite_cluster> BalancerMember http://127.0.0.1:8000 BalancerMember http://127.0.0.1:8001 BalancerMember http://127.0.0.1:8003 </Proxy> RewriteEngine On # Check for maintenance file and redirect all requests RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ /system/maintenance.html [L] # Rewrite index to check for static RewriteRule ^/$ /index.html [QSA] # Rewrite to check for Rails cached page RewriteRule ^([^.]+)$ $1.html [QSA] # Redirect all non-static requests to cluster RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mysite_cluster%{REQUEST_URI} [P,QSA,L] # Deflate AddOutputFilterByType DEFLATE text/html text/plain text/xml BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html ErrorLog logs/mysite.com-error_log CustomLog logs/mysite.com-access_log combined </VirtualHost>Finally, restart apache:
sudo apachectl graceful
If you ever need to stop the processes, use mongrel_rails cluster::stop. If you want the processes to start automatically on boot-up, hit up google again. That's another topic that's pretty specific to the server.