开发者

How do I published a Ruby on Rails application online?

I have a simple Ruby on Rails application that works through a localhost test (bo开发者_StackOverflowth using sqlite, or ruby mysql2 gem). I have a web server ready to upload my app online. I understand that I need to create a new mysql database, which is no problem, and obviously add the connect info in the database.yml, but how do I propertly upload the whole thing (app root) to a public dir of my site?


Rails itself contains a few links to get you started with deployment. I was in your boat a while ago, and I got started with Passenger and Apache within half an hour (although I did have some light Apache experience going in).

Get started just to prove to yourself you can do it

Not that it's a good idea, but the balls to the wall easiest way to "deploy" is the following (assuming you've already pulled your application into your deployment environment, created your database, and run rake db:migrate and any application-specific steps like bundle install on Rails 3):

  1. rails server -p 80 on Rails 3 (./script/server -p 80 on Rails 2).
  2. There is no step 2.

This has to be run on a machine for which you have administrative rights and for which port 80 is not already being listened to by another application. This is suboptimal in many ways, most apparent of which is that it won't allow for virtual hosting (i.e., it won't cooperate with other "websites" being run from that server), but it's a good baby step to dip your feet into.

Go to the machine's FQDN or in fact any hostname that resolves to the machine's IP address (via a hosts file or an A record), and you'll see your application.

Now do it properly

You're going to want to do the following to bring your application "up to speed":

  • Deploy it behind a virtual host behind a webserver application like Apache
  • Use a production-oriented deployment setup (WEBrick's single-threadedness, among other factors, make it unsuitable for production)
  • Actually use the "production" rails environment

I'll be recommending a very, very typical Apache/Passenger deployment environment. The reason is that (at least it seems to me) this particular stack is the most thoroughly supported across the Internet, so if you need to get help, you'll have the easiest time with this.

1. Set up Apache

I don't want to sound like a tool, but setting up Apache (if it's not already set up on your deployment environment) is left as an exercise for the reader. It also varies enough across platforms that I couldn't possible write a catchall guide. Coarsely, use your distribution's package manager (for Ubuntu, this is apt-get) to get it hooked up.

2. Set up Passenger

Passenger installation is even easier. You just run one command, and their guide runs you through all the steps. At this point, in your Rails application root, you'll be able to run passenger start instead of rails s to have Passenger fill the role that WEBrick once did.

3. Hook up Passenger with Apache

The Passenger guide fairly thoroughly documents, step by step, how to set it all up. The ServerName attribute in Apache's VirtualHost entry should be set to your hostname. Passenger will "find" the Rails application from the public directory you give Apache, and when you restart Apache, the first time the server gets a request for a page, Passenger will hook up your Rails application and start serving up files.

I'm not performing these steps as I'm writing this guide, so I'm not sure to what extent this is done automatically, but make sure that the site is enabled via a2ensite (in the case that you're putting this VirtualHost node in the sites-available directory) and that Passenger is enabled via a2enmod.

  1. Make sure your production environment is ready This is likely to be the first time you're using the production environment. Most rake tasks don't automatically act on the production environment, but you can conveniently force them to by including RAILS_ENV=production inline with any rake tasks. The one you'll very likely be running is rake db:migrate RAILS_ENV=production. The bundler in Rails 3 works independently of environment.

5. Go

Restart Apache. The specifics on how to do this will vary by distribution, so you'll have to look it up. For Ubuntu, apache2ctl restart does it for me.

Visit your hostname as you defined in ServerName, and you should be seeing your application up and running.


I've heard gems like capistrano can assist with this.

https://github.com/capistrano/capistrano


Heroku is an excellent (free) option: http://docs.heroku.com/quickstart

Also, deploying to Heroku is as easy as it gets!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜