Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deploy a Rails 3 applications on Windows?

I've been searching for a way to reliably deploy a Rails 3 application on Windows. I'm quite shocked that it seems like there isn't currently any way to do this. The Apache + few Mongrel services solution don't work currently because Mongrel cannot run in daemon mode therefore I can't install it as a mongrel_service.

The requirements I guess should be:

  • A web server compatible with Rails 3.
  • Must be able to run as a Windows service, daemonized.
  • Must be able to restart automatically in case something goes wrong.
  • Must be production quality: no memory leaks, etc.
  • Should be able to scale, and accept multiple requests concurrently.
  • Less hacks possible.

I found out these things:

  • Mongrel is not production ready for Rails 3 (1.2.0pre), I experience memory leaks quite fast from a console window. The app just exits.
  • Mongrel doesn't run in daemon mode (-d) with Rails 3.
  • Therefore Mongrel cannot be installed as a service.
  • Phusion Passenger is not available on Windows (would be the best solution).

These are the possible solutions I came up with:

  • Get a Linux box, install Apache + Phusion Passenger and roll.
  • Using thin, however, the author says the thin process is not 'guarded'.
  • Using Ngnix, however, the author says he just ran a default app, not a full run app.
  • Using Ngnix. I think this solution suffers the same problem as above.
  • Using a virtualization of Linux, but I must solve problems like auto-start, etc.
  • Run on JRuby within Tomcat.

This might be a handy tool: http://projectkenai.com/projects/winsw

I hope we can find a real solution to this issue.


Update:

I agree that JRuby + a j2ee container is the best bet. Some problems must be resolved like gems with extensions, etc. There are lots of valuable ideas here: http://rails-nutshell.labs.oreilly.com/ch14.html#production_r259035_id35801805

like image 941
gamov Avatar asked Mar 11 '11 04:03

gamov


People also ask

How do I run a Rails server on Windows?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .


2 Answers

This is the setup I currently have running:

  • Windows server 2008
  • Apache 2.2
  • Thin Server
  • Ruby 1.9.2
  • Rails 3.0.9

Installation of these aspects is covered by this great tutorial "How to install and configure Ruby on Rails with Windows Server 2008 EE". I ignored the LDAP and ActiveDirectory bit, but there is a nice workaround discussed there for installing Thin server since gem 'thin' will normally break on Windows.

For production I set up MySQL Server 5.5 to host my database. The mysql2 adapter is required for Rails 3 but is not yet supported in my Windows environment. The mysql adapter will also throw an error on Rails 3, but as a workaround you can get it to work by installing an older version of libmysql.dll. You just need to drop it into your Ruby192/bin directory.

Once the proper mysql adapter and server is installed you'll need to create the database:

>> mysql -u root -p  
[enter root pw]  
create database production;  
quit;  

(You may need to add your MySQL installation to your path if 'mysql' cannot be found.)

Finally, set the database config found at your_rails_app/config/database:

# MySQL Production Database
production:
  adapter: mysql
  database: production
  pool: 5
  timeout: 5000
  encoding: utf8
  password: [your_root_password]
  host: localhost

The rest, including the proxy setup and running as a Windows service, is covered at "How to install and configure Ruby on Rails with Windows Server 2008 EE". To make sure your basic Thin setup is running correctly:

thin start -p 3000 -e production

This should start your server on port 3000 in production mode using the MySQL database. The only thing missing here is load balancing, which I'm hoping to find an answer to soon!

like image 150
ChrisOnRails Avatar answered Nov 14 '22 21:11

ChrisOnRails


Personally, I think the JRuby + Tomcat avenue is going to be your best bet, just because Tomcat is vetted on Windows and it along with JRuby are pretty stable. My first thought was Passenger as well, and it's sad that it's still not ported.

like image 44
MattC Avatar answered Nov 14 '22 22:11

MattC