Ruby on Rails and MySql .. on Windows Vista

So, this evening I got the urge to get Ruby on Rails working on Vista, with MySql. I haven’t done much with RoR, but figured I would give it a go. I have this test hosting account that has RoR hosting, so that is what got me somewhat motivated…anyway’s, on with the show.

 

Install Ruby

Installing Ruby is pretty easy. You can follow the tutorial pretty much step by step from the rubyonrails.org site, except it is tailored to *nix machines (Mac, Linux) as far as paths and stuff..

1) Download and install ruby..(http://www.rubyonrails.org/down)

2) get RubyGems, run ruby setup.rb

3) Get rails:…. gem install rails –include-dependencies

Create Application

At the command prompt:

rails c:railsblog

cd railsblog

ruby script/server

test it on http://localhost:3000

if all is well, you will see a cool welcome screen..

Now.. lets actually start making our blog app by generating a controller..(remember , you need to call “ruby” before executing these scripts.. in Mac, etc you don’t have to)

ruby script/generate controller Blog

Then edit your blog_controller.rb and add some code:

class BlogController < ApplicationController
    def index
        render :text => “Hello World!”
    end
end

try it (http://localhost:3000/blog).. whoops.. error?

no such file to load — sqlite3

check under your app dir (c:railsblog) your configdatabase.yml

it is set to sqllite.. we need to get MySql installed and configured

Install MySql (5.0.51a)

This is a whole nother debacle. MySql doesn’t really work right on Vista.

download MySql (http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-essential-5.0.51a-win32.msi/from/pick#mirrors), install it

you will notice.. the config assistant doesn’t run at the end..

Configure It, Hack It, Swear At It

First, in the MySql/bin directory, set both the MySql config assistant and the mysqld-nt.exe to run in XP Sp2 compatibility mode, and run as administrator (this will
allow the service to start once the config assistant is done, once we hack to run anyway’s)

In your application logs in event viewer you will see

Activation context generation failed for “C:Program FilesMySQLMySQL Server 5.0binMySQLInstanceConfig.exe”.
Error in manifest or policy file “C:Program FilesMySQLMySQL Server 5.0binMySQLInstanceConfig.exe” on line 6.
The value “asAdministrator” of attribute “level” in element “urn:schemas-microsoft-com:asm.v1^requestedPrivileges” is invalid.

Nice..

I guess older version work, but 5.0.51a doesn’t. You can see in the error, “asAdminstrator”, it should be “requireAdministrator”, we need to hack the exe..

download resource hacker – http://www.angusj.com/resourcehacker/

Open the MySqlInstanceConfig.exe in Reshack, ctrl+f, search for “asAdministrator”, change to “requireAdministrator” save and compile the exe over the old one..

Whoo hoo! The config assistant runs!

Basically the defaults, except I chose

“multilingual” on the character set screen,

and checked the “Include Bin Directory in Windows PATH” box on the Windows Options Screen

and – setup a root password on the security screen!

after it is all done, I like to secure my local machine, go to the my.ini in your MySql directory, and under the [mysqld] add

bind-address=127.0.0.1

so only local apps can connect..

Test MySql by opening a cmd prompt,

mysql -h localhost -u root -p

hit enter, it will ask for a password , and you should be able to login

Configure MySql For Our App

login to MySql using the cmd above..then

CREATE DATABASE blog;
CREATE USER ‘blog’@’localhost’ IDENTIFIED BY ‘blog';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON blog.* TO ‘blog’@’localhost';
FLUSH PRIVILEGES;

quit

Now we have a database called “blog” a user called “blog” with password “blog”

We need to tie Ruby to MySql now…

run..

gem install mysql

now, you probably have your mysql directory in your path, but since you need to restart your machine or explorer for new paths to show up, it doesn’t work yet..
so we need to make sure we do that, otherwise, if you try hitting http://localhost:3000/blog you will get a libmysql.dll error popup. I just killed explorer.exe and
start->run explorer in task manager, and then hit http://localhost:3000/blog again and saw the “hello world”

Yesssss… it works. Now , for the fun stuff, actually coding and creating tables, and more!!!!

9 thoughts on “Ruby on Rails and MySql .. on Windows Vista”

  1. It says on the blog website (the one you provided that I did) “Sorry but something went wrong” while the regular page is fine!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s