rails 4 on windows

Deploying Rails 4 App on Windows

Deploying a Rails App on Windows is not quite easy like in Linux Environment.
In this tutorial, I will show you how to do it step by step.

Installing Bitnami

Go to Bitnami Ruby Stack Website and download Ruby Stack 2.0.0-23.
Then, install Ruby Stack 2.0.0-23 on your computer.

rw2

Setting up your Rails App for Deployment on Windows

For this tutorial, we will use the Micro CRM app.
We download the app from Github and unzip it in C:\Bitnami\rubystack-2.0.0-23\projects.
Next, we open the ruby stack console and navigate to the micro_crm-master directory:

Then, we add the thin and tzinfo-data gems to the Gemfile:

Then, we run the bundle install command.

rw6

We run the rake db:migrate command to generate the database and then rake db:seed command to seed the data

Next, we precompile our assets using the following rake task:

Then, we set the config.assets.enabled to true in application.rb:

In the terminal we execute the next command:

Finally, we add the generated string to the config/secrets.yml file:

Now it’s time to see if our rails app is running.
We start the thin server in production mode:

Open a browser window and navigate to http://localhost:3000. We should see:
rw8

Creating Windows Services for Rails Server

We create 2 Windows Services using the utility srvany.exe, that will start automatically our thin server in production mode.

First, we install Windows Resource Toolkit that has the utility srvany.exe.
Then, we copy srvany.exe from C:\Program Files (x86)\Windows Resource Kits\Tools to C:\Bitnami\rubystack-2.0.0-23\ruby\bin.

We open the windows command prompt as administrator and run the following commands:
rw9

Next, we run the program RegEdit.
Under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ we found the 2 services that we have just created.

Then, we right click the ThinServerFirst service and create a new key called Parameters.
rw11

We add to this key the following String Values:

rw12

We do the same thing for the ThinServerSecond service . The AppParameters for this service will have the port 3002:
rw13

Finally, we open Windows Services and right click each Thin Service, select Properties and choose the option Startup type: automatic:
rw14

rw15

Load-Balancing with Apache-Server

First, we run our favorite editor as administrator and open the file C:\Windows\System32\Drivers\etc\hosts.
Then, we create a new host called microcrm:
rw20
Then, we open the apache conf file and uncomment the following configurations:

rw17
Then, we add at the end of the file the following configuration:

Next, we set the proxy balancer in httpd-vhosts.conf:

Finally, we restart the apache server with Bitnami RubyStack Tools, open a browser window and navigate to http://microcrm:
rw18

Conclusion

Deploying Rails 4 App on Windows can easily be done with bitnami software.
You can find the apache config files used on this tutorial in Github.

If you have any questions, then feel free to drop me a line.

Happy Deploying!

Leave a Reply

7 Comments

  1. Azzurrio

    I did follow your steps; but I still can’t access my application from the public IP

  2. Ana

    Hi, I followed your tutorial with my own project and wanted to note some things
    (first part with thin)
    1. I had a problem with the css of my project and found out that thin doesn’t handle static assets. It gets solved changing this line in production.rb
    # Disable Rails’s static asset server (Apache or nginx will already do this).
    config.serve_static_assets = true
    2. I’m kind of new with the production part and wanted to ask you if it’s possible to change the localhost address to something like 192.168.3.10 in order to access the app from another device in a local network
    3. I tried to use Apache but when I try to access to my app there’s an “503 Service Unavailable” error
    Unfortunately windows isn’t the best environment for Rails but this is a great tutorial when the client demands this requirement, thanks in advance

    • Ana

      Solved the apache problem, turns out I had to use bundle exec on the thin server command but uninstalling the version of rack I didn’t used solved that. This is in case anybody faces the same issue

  3. banlock

    Hello,
    i still have on my server “503 Service Unavailable” error. Do we agree that i should be able to access to my application after running these services on 127.0.0.1:3001 or 127.0.0.1:3002 ? Thank you in advance for your answer ?

Next ArticleRails 4 Toastrjs Notifications