Is there any good way at all to deploy a Ruby on Rails app built on Ruby 1.9.3 and Rails 3.2.6 with Apache on a Windows machine? I’ve spent hours scouring the forums, but all of the posts seem to be too old to work with the newest versions of Ruby and Rails. Mongrel is no longer under development and constantly causes Rails to crash, thin has only rudimentary Windows support and on my computer causes the Ruby runtime to “terminate itself in an unusual way”, Passenger is Linux-only… I’m kinda lost at this point.
Is there any stable, well-documented solution for serving Rails apps built on the newest frameworks with Apache on Windows?
UPDATE
I finally ended up working out my own solution. Check it out below for an up-to-date guide to Rails deployment on Windows.
UPDATE: I just returned to the company where I deployed with this process. After 11 months left completely unmaintained while the product was in use, the app and server environment are still functioning flawlessly 🙂
Ok, it looks like I finally figured it out. Note that I am deploying to a small pool of users on a company intranet, so my solution may not work for everyone. I am using the excellent Bitnami RubyStack, which contains an integrated Apache/Rails/MySQL installation. From there I did the following (worked for Rails 3.2.6 and Ruby 1.9.3):
Shut down all Apache and Rails (WEBrick/Thin/Mongrel/Unicorn) servers. Exit out of your site if you have any development versions of it open. Clear your browser cache.
If you haven’t already, migrate your database to production mode. From the RubyStack command line, cd to your app’s directory, then run
bundle exec rake db:migrate db:schema:load RAILS_ENV="production". WARNING: db:schema:load will delete all data in your production database.Precompile your assets:
bundle exec rake assets:precompile. Note that this can take a very long time depending on your assets.In your
httpd.conf(for me it’s C:\RubyStack-3.2.5-0\apache2\conf\httpd.conf)Make sure necessary modules aren’t commented out:
Then paste the following code somewhere in the file, with
app_namebeing the folder name of your Rails app and*:82being any port number that Apache is listening to (signified by the commandListen <port_number>:Create one Windows Batch file (*.bat) for each of the Rails servers that your app will be using. Be sure to run them in production mode on the ports in your balancer. For instance, for your first server:
NOTE: The next few steps are necessary because the Rails servers need to run as services, or they will be shut down if there is no user logged in to the server. This also allows them to automatically restart upon failure. However, Windows cannot run Batch files as services, so we have to convert them to Windows EXEs. But standard Windows EXEs cannot be used as services because they don’t respond to the OnStart and OnStop methods. SO, to finally get our servers to run as Windows services, we have to use the Non-Sucking Service Manager as a frontend for our Windows EXEs.
Download a BAT to EXE converter (just google for one) and make EXEs from your batch files. Make sure the converter you get has an option to hide the command windows when it runs (that option is usually called “Visibility” or something like that.)
Download the Non-Sucking Service Manager (nssm.exe). Put it somewhere permanent and add that folder to your path.
Start a command prompt. Type
nssm install <servicename>, where<servicename>is whatever you want your service to be called. You will be prompted to enter the path to the application you wish to run as a service; choose the Windows EXEs you created in step 7, then click install, leaving commandline options blank.Repeat steps 6-8 for all of the ports in your balancer, creating a different service for every Rails server.
Start all of the Services you just created (Start Menu –> Administrative Tools –> Services). The services should start immediately, but you must give the Rails servers at least 30 seconds to initialize.
Start Apache. If it doesn’t start, check to see if you included all the necessary modules (listed in first part of step 4).
Navigate to
localhost:82, substituting your port number for 82 if you customized it. You should see your site looking exactly the same as it did in development.Please let me know if this is too long to be appropriate for StackOverflow. I have just spent quite a lot of time struggling with this problem and figured it was high time someone wrote a up to date guide to Rails deployment on Windows (if there is one, I haven’t seen it yet). Good luck, let me know if anyone has problems or enhancements for this!