I just deployed my first rails app to one of my secondary domains on TextDrive’s shared hosting space.
If that sounds like a recipe for disaster….you’re right!
While Rails is a great development tool, there’s lots of work to do in simplifying, stabilizing, and documenting the deployment process. The app in question is very, very tiny for the express purpose of getting deployment nailed. In fact, it’s taken me longer to deploy than to develop.
For you, and Future Garrick, here’s the process.
- Freeze Rails so you’re not plagued with different-version-itis:
rake rails:freeze:edge TAG=rel_-2-3
- Create an Subversion repository in your primary domain,
Not in your secondary domain. If the repository is in a secondary domain, your primary account can’t see it. Using your primary domain and primary account is easier – if not as tidy as I’d like.
- Give your primary account access to the new Subversion repository.
- Grab the TextDrive deploy.rb from nuby on rails. Verify
- Do the initial import into the repository and an initial checkout back to your local machine.
cd to your local app and run
cap setup. Confirm you now have a
/web/shared directory. It should contain the following directories: log, pids, and system. In
log you should have at least
fastcgi.crash.log. Create and chmod them to 666 if they don’t exist.
- Follow TextDrive’s instructions for setting up lighttpd, rails, and a proxy.
- Change the
/web/public/ paths in APPNAME.conf and rails.sh to
- Follow TextDrive’s instructions to start up lighttpd and rails.
Running their rails.sh file didn’t work for me, editing and manually running the script did.
After all this,
cap deploy will deploy your app for you as advertised.
After I tweak a couple more dials and flip a couple more switches I’ll point you to the app.
Now that I’m just about ready to deploy my first rails app, I thought I’d get the deployment environment set up rock solid on both the production and the development machines (one Mac Mini and one MacBookPro).
Like many other tutorials on this same subject, your mileage may vary. In fact I’m writing this now, because mine did. After stalling out in many of the tutorials all different places, this is what worked for me.
- Download and install MacPorts (used to be DarwinPorts)
- Open up a terminal and type:
sudo port selfupdate
making sure everything is the way it should be.
If you’re like me, you get
port: command not found in return.
- I fixed this by opening up .bash_profile in a text editor (Textmate:
mate ~/.bash_profile) and adding the line
- Next download and install MySQL5
I grabbed the binary from the bottom of the MySQL 5 download page. It comes with a System Preference Pane and checkbox for auto-startup. I’m using CocoaSQL for admin.
- Change the MySQL5 root password
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h [HOSTNAME] password 'new-password'
- Next load up the Apache2 package
sudo port install apache2
(this takes a while)
sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist to launch Apache2 on startup. I’ve disabled Apple’s default Web Sharing in the System Preferences.
- Create an initial http.conf file
sudo cp httpd.conf.sample httpd.conf
- Start up Apache2
sudo /opt/local/apache2/bin/apachectl -k start
- Load up http://localhost. It should say “It works!”
sudo port install fcgi
sudo port install lighttpd +ssl
sudo port install mod_fastcgi
- Next load up Subversion package with the mod_dav_svn for Apache2
sudo port install subversion +mod_dav_svn +tools
- Next load up Ruby, RubyGems, Termios, RB-MySQL5 Bridge, and ImageMagick Packages
sudo port install ruby
sudo port install rb-rubygems
sudo port install rb-termios
sudo port install rb-fcgi
sudo port install rb-mysql (I had some errors on this one.)
sudo port install imagemagick
- Install a bunch of useful gems, like rails and capistrano.
sudo gem install --include-dependencies rake
sudo gem install --include-dependencies rails
sudo gem install --include-dependencies termios
sudo gem install --include-dependencies capistrano
sudo gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies
sudo gem install --include-dependencies mongrel
sudo gem install --include-dependencies mongrel_cluster
sudo gem install mysql --
(thanks to d. robert adams for the last bit)
- Create a rails app
- Connect the rails app to mongrel
mongrel_rails cluster::configure -e development -p 8000 -a 127.0.0.1 -N3 -c /RAILS/ROOT/OF/TESTAPP
I’m walking through the latest beta version of Agile Web Development with Rails 2nd Edition, specifically the new bits on deploying Rails apps. Capistrano – the preferred and recommended deployment utility. Thing is – Capistrano hinges on Subversion. Not something covered in AWDwR or appropriate to be covered. There’s plenty of other books on the subject.
Though, that left me stuck on how to set up a Subversion repository and access it.
I do my hosting at TextDrive, and in the interest of making this process just a hair simpler, I set up my svn repository there. Here’s how I did it:
- Set up repository on TextDrive domain in
There’s a ‘subversion repository’ menu option right when you sign-in.
- Assign svn access rights to a TextDrive domain user.
It’s a radio button and select list selection in their profile.
- Install Subversion on your local Mac – I did via macports
- Install svnX and in svnX preferences, confirm your path to svn in svnX (macports uses
- Import your project into the TextDrive repository
svn import /Users/your/local/path/to/the/app http://[your-domain]/svn/[repository-name]/ -m 'initial import' --username=[your-svn-account-name]
- Connect svnX to the repository
- Check out your project back on to your mac by clicking the ‘svn
export‘ button and picking a directory to put it (not your original directory). I created an
/svn directory within my main project directory.
- Now, if everything worked, double-clicking the repository should load it up in a new window.
- I’ve got a weird proxy between me and the internet right now, so I’ll make sure the commits work tomorrow. UPDATE: Yep, it works. Yah!