4

I need to set up a dedicated server for a Rails app. I am not sure what is the best approach for this. I need a solution that can scale with lots of users signing up on a site. I guess it would be a medium-scale application.

Here are more specific questions:

  • The OS would probably be ubuntu 10. should I go for ubuntu 10.04 or 10.10?
  • Should I install ruby, and consequently all of gems for the app using sudo, or should i use rvm? If there are no costs for an rvm install, I think that would be preferred as that has greater flexibility, but is using rvm a good solution for a production server? I really have no idea about this
  • Should I use nginx/unicorn, or nginx/passenger, or apache/passenger, or something else?
  • I would need a scalable database, so probably postgres would be better than mysql. Or should I go along with something else, or change my preference here?

One related question, though not related to this post directly: I typically always install one ruby system-wide using sudo, and install packages like libssl or whatever, and then install the others using rvm without sudo. Is this the correct way, or can i directly install all rubies i need with rvm without one installed system-wide as well?

Ravindra S
  • 6,302
  • 12
  • 70
  • 108
umar
  • 4,309
  • 9
  • 34
  • 47
  • 5
    The answer to all these questions is "sure" unless you can give more context on the type of application you're deploying. This is about as generic as "I need a car, what kind should I get?" – tadman Nov 03 '11 at 15:30
  • 1
    definitely use rvm. Ubuntu packages for ruby were deprecated the last time i checked (they used to install an ooooooold version of ruby). Rvm lets you choose between system-wide and one-user-only install. But as @tadman said, you really should be *more specific* about what are your needs, what kind of load you expect your app to withstand, what is its purpose, etc. – m_x Nov 03 '11 at 15:52
  • @tadman and m_x: for a medium-scale application. actually the ubuntu version, or the centos version if we use taht is not that important, the more important question is whether rvm should be used with sudo, or without, or should i use ruby without rvm. and then, is nginx more popular in the rails community than apache, or vice versa. and why? – umar Nov 03 '11 at 16:18
  • I think using rvm as root is fine and haven't had any trouble doing it. `rvm` will do a better job of installing the correct version of Ruby and patching it than whatever distribution you're using. – tadman Nov 03 '11 at 18:22
  • Try to be root as little as possible. Your application *definitely* should not run as root, of course. – Marnen Laibow-Koser Nov 03 '11 at 18:44

4 Answers4

6

I was in this same predicament only last week, the solution I took was to follow Railscasts #335 Deploying to a VPS

Ryan Bates walks you through the tricky steps of deploying to a VPS though, I have deployed to a dedicated server I set up at home to learn the deployment process.

He uses the following setup:

  • Ubuntu (10.04 LTS)
  • nginx (1.0.14)
  • Unicorn (4.2.0)
  • PostgreSQL (9.1.3)
  • Postfix
  • rbenv
  • rbenv-installer
  • Capistrano

Personally, I am better equipped for MySQL and so easily used that in place of PostgreSQL. I also used Ubuntu 12.04.

Admittedly I did pay the $5 subscription. But to be honest the trickier parts of deployment are also covered in more depth on other tutorials. He gives you source code and clues you up on other aspects such as good tools (such as the rbenv-installer).
This also got me using rbenv rather than RVM as I had been using previously and so far i have had no issues with it.

One thing I did trip up on though and had to find some external input on was unicorn but this post along with the Railscast on Capistrano helped me nail it.

Good luck

Community
  • 1
  • 1
DazBaldwin
  • 4,125
  • 3
  • 39
  • 43
4
  • Use RVM. See http://beginrescueend.com/integration/passenger/ .

  • I would use Nginx and Passenger -- Passenger is incredibly easy to set up, and Nginx is nice and lightweight.

  • Postgres is way better than MySQL in nearly every respect. Good choice.

Marnen Laibow-Koser
  • 5,959
  • 1
  • 28
  • 33
  • MySQL is significantly easier for a developer to use, and it has more tools available for management. Although Postgres is arguably a much better database platform, it requires a larger investment of time on the part of the developer to learn and manage. – tadman Nov 03 '11 at 18:24
  • Not particularly true in my experience. I've used both extensively (in fact, I switched to PostgreSQL after many years of pretty advanced MySQL work). Postgres is slightly harder to set up, but repays that initial investment many times over. I haven't missed any MySQL management tools. What specifically are you thinking of? – Marnen Laibow-Koser Nov 03 '11 at 18:44
  • My biggest grievance is that PGAdmin is a terribly user unfriendly application on any platform and that the Postres schema environment is unnecessarily complicated, something that confuses less sophisticated developers. Where MySQL has little more than databases and tables in most cases, Postgres has a number of other layers that in most instances are irrelevant. While this gives the developer significantly more control, it does require additional learning to use effectively. – tadman Nov 04 '11 at 15:13
  • Postgres's schemas are actually a nice thing to have, though there's no good way that I know of to use them with Rails. I don't find myself using PGAdmin much at all (and there *are* other graphical tools for Postgres), but in any case, you shouldn't be choosing your DB server based on graphical clients. It sounds to me like you may not understand how to use Postgres effectively... – Marnen Laibow-Koser Nov 07 '11 at 15:08
  • It's not a case of not knowing how to use it effectively, but that there's more to learn, and for junior developers they can make a mess of it if they're not as savvy. Hence "MySQL is significantly easier for a developer to use". Postgres is better, but better comes at a price. – tadman Nov 07 '11 at 15:31
  • It's hard to make a mess of Postgres: if you don't set it up properly, it will fail fast. MySQL, OTOH, has lots of hidden gotchas and things that look like they work but actually don't. So MySQL *looks* easier to use, but in fact is *harder* because it's less predictable and less capable. Any developer who can't deal with the slightly harder initial Postgres setup shouldn't be a developer. – Marnen Laibow-Koser Nov 07 '11 at 15:42
  • To be fair there is a difference between a "developer" and a proper DBA, but you have a point. – tadman Nov 07 '11 at 16:14
  • Absolutely. I'm a developer. I'm definitely not a real DBA. Everything I've said here is from that perspective. – Marnen Laibow-Koser Nov 07 '11 at 16:57
1

I'd choose unicorn over passenger, if only because passenger still doesn't offer rolling restarts.

That means any time you deploy, all the instances get taken down at the same time, and then brought back up. You won't drop any requests, but may get 10-20 second page loads for anyone hitting your server when you deploy.

klochner
  • 8,077
  • 1
  • 33
  • 45
0

Your post contains multiple questions, so let me address them one by one.

RVM

I do run a Rails application in production with RVM (standard setup, not the root thing). So far I haven't experienced any issues.

Pro:

  • It's easy to have the same environment as on your development machines
  • Greater flexibility on Ruby and Gem versions

Con:

  • Cron jobs or shell scripts might need some more attention (see here). However, I haven't had any big problems with that

Maybe you can give a bit more details about the problems you've heard of?

OS

As other people pointed out already, it doesn't matter that much. Personally, I prefer Ubuntu LTS versions for servers. The most recent one is Ubuntu 12.04 LTS, so I would go for that.

Web Server, Database

It's really hard to tell based on the few information you gave. The options you listed all have their pros and cons, but I'm not sure whether they really matter to you at this stage of the project.

I'd recommend choosing the technology you are most familiar with. (If you are not familiar with any of those, choose Apache/Passenger and MySQL.) Later on when you've got thousands of users, you can always switch. Just don't put too much effort in optimizing the architecture beforehand. Get something up and running!

claasz
  • 2,059
  • 1
  • 14
  • 16
  • To elaborate, RVM is great for development, but some of the problems I've heard (and already encountered) with trying to run RVM in production is that it is too bleeding edge so there might be a bug, since RVM is all about modifying shell variables you will have a harder time trying to load Ruby and gems (even using bundler) and passenger only lets you run one Ruby version and does not play nice with RVM, so you have to create special load scripts to tell passenger to load gems through RVM. – Andrew Jul 13 '12 at 15:03
  • And I've heard rbenv is better suited for production because it doesn't modify your shell (but not as easy to use in development). – Andrew Jul 13 '12 at 15:03
  • 1
    Actually I managed to install Passenger together with RVM without any special load scripts. Have you checked http://everydayrails.com/2011/01/25/passenger-3-rvm.html? – claasz Jul 13 '12 at 15:23
  • @Andrew RVM isn't bleeding-edge. It's stable and has been around and well supported for years. I have used it with Passenger on my servers for years, without a single problem till 2 weeks ago. – Marnen Laibow-Koser Feb 18 '13 at 13:46