Correct way to set up Rails environment? - ruby-on-rails

Thanks Tilo for your response. I will try to ask a better question.
I need to set up a Ruby on Rails Production environment that will only be used to host RoR applications and will be used as a Git server too. There will be no development done to these applications on the Production server. Right now, I forsee the production server hosting a maximum of 5 to 6 applications only. A couple will be company internal only and the rest of the apps will be viewable to the public. The traffic that they will receive is about 12 to 20 hits per week.
I have been given access to a Virtual Machine that will be the Production server and is currently running Ubuntu 10.04 LTS, Apache2, MySQL, and Passenger. There will be two RoR developers using the Production server to host their applications.
My Development Environment of which I am running Ubuntu 10.04 LTS, Apache2, and MySQL on my own laptop looks like this for each project/application:
RVM installed per application, Git,
Ruby 1.9.2 installed thru rvm, Rails
3.0.3, and I have yet to install the Capistrano gem.
My question is I don't understand how to host a RoR application on our production server.
As an example of what might be done to host a RoR application: I am surmising that I will create a user called app1 under the home directory. Next, should I install Ruby system wide or should I install rvm for app1 and then Ruby for app1? What are the steps involved on how to set-up the environment to run an application on a production server?
Can you give me a few setup scenarios, please?
Thanks in advance.

You didn't tell us what you want to use this web-site for... is it company internal only?
just a few users? or is it externally facing the internet? Just one server running everything?
If it's facing the internet, I would certainly stay away from Ubuntu... look at CentOS/RedHat or FreeBSD to install on a production server.
I'd definitely use Capistrano for deployment. Definitely Git.
I would definitely not install RVM system-wide - IMHO it is not robust enough.
I emailed with Wayne Seguin (maker of RVM) and he also uses the method I've outlined in the post below,
using one dedicated deploy user:
For how to deploy ruby-versions and gems with RVM, look at this post:
Installing Ruby offline using rvm
If you really need two versions of Ruby for two different apps, then use two deploy-users!
Each of them has their own default-ruby-version(!) that's why you really need two users :)
and you can install / manage the gems for each project separately under each of the deploy accounts.
You should also put the git repository in each of the accounts, so you can test.

Related

Ruby on Rails: How to deploy an app on remote linux server

I have a working ruby on rails app in my local machine running on localhost(REST APi's). I want to deploy it on remote linux server.
I searched it over google, All I got was installing ruby, rails, nginux and others. It's really confusing. To make my app to work in rails environment in linux, is it really necessary to install the entire ruby and rails. Or, is there any binary executable available where we can use it without installing.
What is minimum required software to install or configuration needed to be set to make my app work in production environment?
(For Example, when I deploy nodejs app, All I need is to put the linux nodejs binaries in server without the need for installing the entire nodejs software)
Any help is appreciated!
The process of setting up your production server will be pretty much the same as with setting up your development machine in terms of installing Ruby and its dependencies. There are no binaries that you can just copy over. In addition to that you'll have to install and set up a web server like Apache or nginx.
I recommend this guide by Digital Ocean. It goes through everything from installing ruby, to setting up the database, to configuring the web server.
They have a couple more (here and here), which seem to be very similar, using different application and web servers, but I haven't read them.
You need to do the following:
1) Ensure that you have an installation of the Ruby language, either via your Linux package manager or with rvm or the like. I recommend it be a recent version (2.2+).
2) Copy over your Rails source tree.
3) gem install bundle
4) bundle install (in the project root directory)

How to deploy a rails project on a Ubuntu server?

I've developed my Rails project locally and want to deploy it on my Ubuntu VPS. Now I've installed the gems on the VPS and copied my Rails App code to it. I can execute rails s --binding=0.0.0.0 in a putty session to the VPS and the website can be access from the Internet. The problem is when I close putty, the website is down. How to start my Rails App in a way that it still alive even if I closed putty?
Using rails s is not the way to go. It will use Webrick(or a different one if you choose) to handle the requests and it can be quite slow.
You should setup a production stack for serving your website.
Here is one of the best tutorials I've seen about how to deploy a Rails app to a production server(VPS).
In short you gonna need install RVM or Rbenv, Ruby, some libs, Database, Nginx and Passenger. You have alternatives too. But this is the basic.
I recommend using Capistrano for deploy. You can choose another deployment tool also, or none.
rails s it is best for development only.

Multiple Rubies under apache in production server

I want to run multiple rubies on our production server. We have some ruby 1.9.3 rails 3.2 sites going live as well as keep older 1.8 sites. I understand that Passenger 3.2 will be able to do this natively but isn't live yet.
So for now, is this the best way to do this?
http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
The apache passenger module can't do this. You could however run passenger standalone for each app (with a different ruby version) and then proxy from apache to passenger standalone.
You could of course also proxy to unicorn, thin etc.
What about using multiple VMs/Slices for your different versions of ruby and rails, that way you have more control of your enviroment and don't have to worry about your different rubies/rails causing headaches with each other.
EDIT
Another solution that I have heard of but haven't tried is setting multiple users and running each version of ruby/rails per a different user

Can I deploy a Rails App directly onto my companies website?

I have originally been hosting my apps on Heroku, however this is not an acceptable deployment method in my current environment. We have personal information in our applications that deploying to Heroku and setting up DNS forwarding is not acceptable. Regardless of how 'secure' or 'reliable' anyone may think it is, it is just not acceptable in my case.
Our host is siteturn.com, integrated with Plesk 10.4.4. If I SSH onto our websites server as admin and type
ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux].
rails -v
Rails 2.3.5
It appears Ruby and Rails are already installed (Older versions than I require, as I need ruby 1.9.3 and Rails 3.2) If I'm not mistaken it seems like my host 'supports' rails (why else would it already have it installed :P).
How should I go about deploying my application directly onto my companies website?
Heroku is an awesome service but the ease of deploying to Heroku has given you a skewed view of what is involved in hosting your own rails website. Heroku has shielded you from a lot of the hard parts.
For example, just because ruby and rails is installed does not necessarily mean you can host a production rails website. You'll need a rails specific web server (for example nginx and passenger, unicorn, etc). You also need a database (MySQL or Postgres) assuming your web app uses one. Also, as you said you need to upgrade the versions of ruby and rails.
That's just to get the server setup. After that you can get to the deployment part. Capistrano seems to be the most popular choice right now.
Take a look at this railscast episode on deploying to a virtual private server for a very good overview of what is involved. It also briefly goes into Capistrano as well. It's not a free episode but I feel it's definitly worth the money.
Pick up a copy of Agile Web Development with Rails, Third Edition and read what it says about deployment. That should get you started. There's more info required than can be put in a SO answer.

Requirements to run Ruby on Rails on Server

I want to develop a website using Ruby on Rails.
What is the requirements for the Server, i.e. what do I have to tell the admin what I need. I believe the server will be running on a machine that is already hosting some websites which use PHP. I dont know more about that so far, and it will probably be depending on my requirements.
As far as I understood from documentation and other questions the server needs to have ruby, rails installed. It also said that I could use cgi.
My problem is that I need a concrete list of things that my admin should provide.
Another question suggests that the only thing is to intall Phusion Passenger if I can use an Apache Werbserver. This would seem like an option maybe.
So what do I really need?
Phusion Passenger is the easiest way to go in a mixed environment.
A Rails app needs these things:
ruby (ruby enterprise edition or MRI 1.9.2)
rubygems
sort of gems handled with bundler
You should try it with Passenger on Your local computer. Then you will see the list for the installation.

Resources