Getting Typo 4 running on DreamHost
Posted by Aiden Bordner Mon, 24 Jul 2006 23:37:25 GMT
This has been an interesting day, attempting to get a fresh build of Typo 4.0.1 installed on a shared hosting account with DreamHost.
The reason for this, predominantly, was to practice deploying a Rails application on DreamHost in preparation for the launch of Witnessing Life which I’m currently spending my days (and nights) thinking about.
Without further ado, here’s the rundown of how I achieved my goal.
Disclaimer: I am not well versed in server configuration, ruby, rails or typo. This is simply a documentation of the steps I took to get typo up and running on my page. I am a newbie with the intention of helping other newbies get their feet wet. If things go wrong, see the list of related links at the bottom and seek assistance at #typo on irc.freenode.net, but more importantly please let me know what went wrong so I can correct this information for the future.
Another Note: This post is under the assumption you’re installing your blog as a subdomain, like this blog, e.g.: blog.yourdomain.com.)
1. Install using Subversion (not gems)
Although the Typo folks were kind enough to create a RubyGems installer, you can’t install your own gems (easily) with DreamHost. (To do so requires creating your own gems install on your account. I followed the DreamHost wiki to this effect, but it did not work properly; I think a misconfiguration in the bash_config). Regardless. it proved easier to use subversion and install from the typo trunk. Use your terminal to SSH to your server (e.g., ssh yourusername@your.website.com) and enter the following into the command line at the dreamhost server.
svn checkout svn://typosphere.org/typo/trunk typo
This is going to take a while. Bounce over to your browser and go on to step 2 (or get a sandwich).
2. DreamHost Setup
You need to configure a subdomain for Typo. Under the DreamHost Control Panel choose “Domains > Manage Domains” on the left hand side. Then configure a subdomain with blog.yourdomain.com as the domain, FastCGI enabled and a directory of home/username/typo/public. Save your settings.

You also need to create a database where typo is going to store your posts, etc. I’m using MySQL. Under “Goodies > Manage MySQL” you can create a new database, for instance “typo_db” with a username of typo and a subdomain of mysql.yourdomain.com Create an original and strong password and save it for the next step.

It’s going to take a 10 or so minutes for your new subdomains to propagate on the dreamhost DNS servers, and some of the following steps to work properly (namely for typo to find the database, since DreamHost wont accept localhost for a MySQL server). If you haven’t already had that sandwhich, now might be the time.
3. Configuring Typo
The next step is to configure typo to work with your account. Enter the following in the command line:
cd ~/typo
pico config/database.yml.example
This is an example version of the database.yml for mysql. You want to edit this file to match the settings you just created.
Under the ‘login’ callout, change host to mysql.yourdomain.com, change the username to typo (or whatever you set the mysql user to be in step 2) and enter the strong password from the end of step two where it says password.
You also need to change the name of the database (marked database) under each of the three application modes (development, test, production) to your newly created db, typo_db.

Type ‘Control-X’ to exit. When it prompts you to “save modified buffer”, type Y. Pico will then prompt you for a name for the changed file. Remove the .example from the end of the filename, naming the file database.yml.
Next, at the command line, type:
pico config/environment.rb
On the fifth line, uncomment the line that reads ‘ENV[‘RAILS_ENV’] = ‘production’ (remove the ‘#’ from before the line). It should look like this:

This will force rails into production mode for DreamHost. When complete, type ‘Control-X’ to exit and save the file with the same name.
Finally, back at the command line, type:
rake migrate RAILS_ENV=production
This will take a while, but it will get the database schema configured on the typo_db MySQL database.
Note: If you have problems here and the output indicates the rake script was looking for a typo_dev database, you need to restart your rails processes on your dreamhost account. To do this, try ‘killall ruby’ and try again.
4. DreamHost Tweaking
If everything has been going ok so far, there’s just a few more things to do for you to be Typo Powered.
We need to edit a couple more documents:
pico public/dispatch.fcgi
First of all, change the top line that reads ’#!/usr/bin/env ruby’ to ‘#!/usr/bin/ruby’. This, called the “shebang” line, is the path to ruby, and DreamHost’s path is slightly different than the default.
Next, scroll down to the bottom of the document and look for the line that reads ‘require fcgi_handler’. Underneath that line, add the following code:
class RailsFCGIHandler
private
def frao_handler(signal)
dispatcher_log :info, "asked to terminate immediately"
dispatcher_log :info, "frao handler working its magic!"
restart_handler(signal)
end
alias_method :exit_now_handler, :frao_handler
end
This is a method of dealing with intermittant 500 errors at DreamHost devised by Alex Young. When you’re done, the file should look like this:

Hit ‘Control-X’ and save your changes again. Now we do the same shebang line change to dispatch.rb:
pico public/dispatch.rb
Again, if the top line reads ’#!/usr/bin/env ruby’ change it to ‘#!/usr/bin/ruby’. Close and save.
Finally, we have just a few permissions to set. At the command line:
chmod 755 public
chmod 755 public/dispatch.fcgi
chmod 755 public/dispatch.rb
And you’re done! At this point you should be able to go to blog.yourdomain.com and create your first user. Note that, at first, the response of the system may be a bit sluggish. This is because the first time the controllers are accessed they haven’t yet been cached. You should notice a performance increase quickly through use.
Again, I am a Ruby/Rails/Typo amature myself, so if these instructions don’t work, my appologies. Please let me know and I’ll revise them. Additionally if you are a pro at this and notice I’m doing something wrong, please let me know and I’ll happily correct it.
That said, my experiences were based on trial and error and a lot of help from the following:
DreamHost 2.6 Installation on TypoTrac
Official DreamHost Wiki for Typo
Alex Young’s DreamHost 500-error fix

Your link to www.typosphere.org is broken -- just so you know. (-: Blog nOOb!
Missing a 'w' (oops) ... fixed now. :)
Hey, first of all, thanks for the post, i been trying to get typo running on dreamhost. I follow the steps but when i get to thew RAKE part, something goes wrong. These is what i get: [redhot]$ rake migrate RAILS_ENV=production (in /home/.governor/orlybg/typos.highiqsolutions.net) rake aborted! Access denied for user 'orlybg '@'redhot.dreamhost.com' (using password: YES) (See full trace by running task with --trace) I dont know what to do next, i'll apreciatte any help, thanks in advance. Orlando.
Finally i get typo running on Dreamhost, thanks a lot!
Excellent write-up .... but your link to www.typosphere.org is still broken needs to be dot org NOT dot com
Thanks Adien I used your guide and it worked great the Dreamhost Wiki for Typo really didn't work at all for me and your guide worked like a charm. The only thing I did different was used VI instead of PICO :) Eric sends
I've followed your instructions step by step but for an unknown motive I was getting the error message "Access denied for user X to 'database typo'" doing the migration, so I've deleted the typo_db database and I've created another one called just typo, and everything is now working ok.
Installed Typo - it's up and running except ..... It's URL is www.blog.mydomain.com/typo/public when I want it to be at www.blog.mydomain.com What did I do wrong? And do you know how to fix this? Thanks for the great tutorial!!
Hi, many many thanks for the very clear guidelines. I had one glitch - on rake-ing, it aborted with the following: private method 'gsub' called for nil:NilClass however, as I found at blog.kibara.com, this was due to this line in db/migrate//051_fix_canonical_server_url.rb b.settings['canonical_server_url'] = b.settings['canonical_server_url'].gsub(%r{/$},'') which I commented out, and then ran the process again - it worked fine.