-- Installing Typo on Bluehost -- 7

Posted by Bart Mon, 07 Aug 2006 07:08:00 GMT

Firstly, you should check out the RubyOnRails guide to your first Rails app here.


Secondly, you should checkout Bluehost’s page on getting started with Rails on their server, here.


Thirdly, check out the Bluehost Forum for information. My experience has been that the posts here are a good start, but alone do not answer any questions in depth. There’s a lengthy post on Typo which is a good start.


Also, Paul Sturgess has a good artical on Rails, and as of this writing, hosts his site with Bluehost.


-- Installing Typo on Bluehost --

Typo is the 2nd Ruby On Rails app I’ve installed on Bluehost, but it’s the first which isn’t mine. The first was straight forward, I followed the Bluehost instructions found here

The second, is this version of typo you’re hopefully reading right now... hopefully… otherwise there’s a problem... So here’s how I got it done.

When I was initially installing Typo, neither Gems nor Rake worked for me, not sure why yet. I had to download and install Typo manually. This is easier to do with through the shell, but it's not necessary. If you want it, Bluehost requires that you provide some additional info to them in order to get shell access. Mind you that while it’s not absolutely necessary to have it, it is EXTREMELLY helpful. The following steps will allow you to install Typo, and other apps without the shell. Also, using the link command to redirect which folder a browser ends up might be a bit more difficult, although I heard it is possible through the cpanel.

Okay, so here’s how I did it…


-- Getting the code --

Gems complained with"ERROR: While executing gem ... (Errno::EACCES)". This was because mongrel needed to be installed , but couldn’t get done. I guess I didn’t have proper access to the ruby gems directory. At 2:00 am, it was time to hack my way through this install, instead of worrying what Bluehost had installed or not.

Create a directory to store your code. I created public/html/work. Download the code from rubyforge.org using an ftp utility and put it into public_html/work. In the shell, you can run the following command from that directory:
$wget http://rubyforge.org/frs/download.php/11908/typo-4.0.0.tgz

# Untar the code and setup your directories:
$tar -xzvf typo-4.0.0.tgz
$rm -rf ~/public_html/blog

If you want to have typo on a subdomain (blog.mysite.com), create it using cpanel. It will exist with a folder in your public_html:
$ln -s ~/typo/public ~/public_html/blog

If you want to have typo right off of your domain (www.mysite.com), first create an addon domain using cpanel. Next, delete the addon folder in public_html that was just created, and link the same name to typo’s public folder:
$rm -rf ~/public_html/blog
$ln -s ~/typo/public ~/public_html/blog

Note:

  • rm –rf removes folders even if there’s content in them
  • ln –s creates a symbolic link. So when your browser opens up your site, the server directs it to your public_html/domain folder, which is “symbolically” pointed to typo/public

-- Create the necessary databases --

You can create the development database and use it by default, or you can jump right into production. You’ll need to update some files to point to production, as development is set by default. I list the changes a little further down.

Use phpMyAdmin to setup your dev or prod database, as per bluehost’s instructions here.


-- Creating Tables --

Rake did not work for me so I had to do the database set up manually. This just meant running the contents of the sql schema in /typo/db/schema.mysql.sql, via phpMyAdmin on the USERNAME_PRODDB database. Open the SQL tab, and copy/paste the contents of this file right in, and press “Go!”. It should have created all necessary tables.

In the shell you can execute this command from the typo directory:
$mysql USERNAME_PRODDB -DBUSER -PSW </db schema.mysql.sql

Next you’ll need to update the /typo/config/database.yml which tells typo what your database is, and what the login parameters are. This is standard for any Rails application.

Now there’s a catch here with the databases. phpMyAdmin did not synchronize with the /typo/config/database.yml file right away. I spent quite a while trying different configurations before realizing that the results were inconsistent and that something was simply not synchronizing. It would sometimes synch after several (approx 15) minutes, or not at all. I’ve been told it might be a version issue. Bluehost currently has the mysql 2.7 gem installed. The solution is to force the database to synch by re-adding your db user into the database. Recreate the same DB name and password you used originally, overwriting the one that’s there, without deleting the original (just override). This will force the databse to resynch and pick up your database.yml changes. The yml file should of course be in synch with your database.


-- Setting Typo to Production --

Add the following lines to these files:
typo/config/environment.rb
ENV['RAILS_ENV'] = 'production'

typo/public/.htaccess
SetEnv RAILS_ENV production

-- Application Error --

'Application error. Typo failed to start properly' This would occur periodically. It can be caused by many things, but because it occurred periodically, I thought it might be a performance issue due to the lack of FastCGI and paths. After making the following changes, I haven’t received the message.

Set dispatcher path in "typo/public/dispatch.rb" Old Line:
#require "dispatcher"
New Line:
"/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/dispatcher"

-- FastCGI --

Bluehost has Fast CGI installed, you just need to point your app to it. typo/public/.htaccess Content (comments optional):
#*************************
# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
#Options +FollowSymLinks +ExecCGI
#-----------------------------------
#*************************
SetEnv RAILS_ENV production
#-----------------------------------
#*************************
RewriteEngine On
#-----------------------------------
#*************************
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] #
#-----------------------------------
#*************************
ErrorDocument 500 "<h2>Application error</h2>Typo <br />failed to start properly"

-- CHMOD 755 --

One last thing!!! Remember to give everything in the typo/public/*.* folder CHMOD 755 access. Otherwise you won’t be able to access anything through a browser.

Some FTP applications set fields to 644 by default. Watch out for this when uploading quick changes and all of the sudden your app is not found at all.

Comments

Leave a response

  1. Bart Mon, 25 Sep 2006 17:52:37 GMT

    Hi pocius… here’s what I have:

    – MySQL setup –

    Blue host puts in your login automatically followed by a ‘_’ then the db name you provided. But if you called your db ‘typo_dev’.. bluehost will call it ‘login_typodev’. Notice they remove your ‘_’ and proceed the whole thing with ‘login_’. That’s what you’ll need to add to your database.yml file.

    Also, you’ll need to set up a user, and assign it “ALL” access to your databases. The problems I descibe with synchronizing my yml file and databases, describe re-adding this user name. You do this under the ‘MySQL Databases’ screen.

    – database.yml –
    development:
     adapter: mysql
     database: login_typodev
     username: login_xx
     password: password
     host: localhost
    
    production:
     adapter: mysql
     database: login_typoprod
     username: login_xx
     password: password
     host: localhost
    



    Bart

Comments