Reputation: 11
I have a simple Ruby on Rails application that works through a localhost test (both 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?
Upvotes: 1
Views: 3944
Reputation: 18024
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).
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):
rails server -p 80
on Rails 3 (./script/server -p 80
on Rails 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.
You're going to want to do the following to bring your application "up to speed":
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.
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.
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.
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
.
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.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.
Upvotes: 5