Installing Rails with MySQL on Windows 8

Rails on Windows development is easier then it was 2 years ago, but still, there are little gotchas regarding mysql, coffeescript and ssl.. these are some notes taken while installing.

Install Rails

Download and install RailsInstaller to “C:\RailsInstaller”

This will also install Git, and DevKit (require to install gems).

Press WindowsKey+’x’, then ‘a’ (command line admin), execute these lines in the terminal to update the gems:

gem update --system
gem install bundler
gem install rails

Install MySQL & mysql2 gem

Download and install MySQL 5.5

In the command line:

gem install mysql2

Download the connector-c relevant to the gem version.

(http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick in my case)

Copy “libmysql.dll” from the zip file lib directory to “C:\RailsInstaller\Ruby1.9.3\bin”

That should work. If it doesn’t, you can try to install the gem with this command:

gem install mysql2 --
     '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib\opt"
      --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'

And copy the “libmysql.dll” from “c:\Program Files\MySQL\MySQL Server 5.5\lib"

If that doesn’t work too.. may God have mercy on your soul :)

Install Nodejs for CoffeeScript compiling

As the time of this writing, CoffeeScript compiling doesn’t work out of the box with windows 8 (Rails will give an error on application.js compiling, even with empty coffeescript files).

So we need to install node.js, Rails will use it to compile.

Remove webrick annoying warnings

We need to apply keep-alive patch

This will remove “WARN Could not determine content-length” messages from the webrick server (what you get when you start “rails server”).

Open file “C:\RailsInstaller\Ruby1.9.3\lib\ruby\1.9.1\webrick\httpresponse.rb”.

Change line 205 to:

"        if chunked? || @header['content-length'] || @status == 304 || @status == 204"

Fix SSL issues

“OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed”

sIf you try to connect to APIs that use SSL (like facebook api via koala), you need a certificate.

  1. Download http://curl.haxx.se/ca/cacert.pem to “C:\RailsInstaller\”

  2. Press WindowsKey+’x’ then ‘y’ (system), choose “Advanced system settings” to the left.

  3. You are in the advance tab. Press “Environment Variables” button on the bottom.

  4. In the “System Variables” section, add a new variable name “SSL_CERT_FILE”, value “C:\RailsInstaller\cacert.pem”

(credit to this gist)

Verify Rails

Reopen the terminal

Generate new Rails project with mysql:

rails new Blog -d mysql

Edit config/database.yml and enter the mysql username/password of your installation.

Create db and a model to verify mysql connection:

rake db:create
rails g resource post
rake db:migrate
rails c

# inside the console
irb(main):001:0> Post.all
Amitkaz?size=bigger
My name is Amit Kazmirsky,
I'm a Ruby On Rails Consultant.