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)
Related
I have a rails application that I'm trying to use on other machines that do not have ruby, rails, or bundler installed. Is there a way I can zip up the rails application, the ruby environment and all its gems / dependencies? I'd like to be able to just send the zipped file to a computer without ruby and be able to run the application without having to install ruby, rails, bundler and all the gems in the rails app.
I've tried traveling-ruby, but it just packages ruby and not rails or bundler.
Edit: For clarification, the app is an internal tool for work. We would rather not deploy the app to a server, but rather just share the whole package with computers that may or may not have the dependencies installed.
You should consider Docker to prepare a "package" of self sufficient environment for your application. This way you will be able to send it to another machine and run without problems. You can use those containers for development purposes only. There is no requirement to deploy them into a server.
I am new to Ruby on Rails (coming from C#/ASP.NET). My question is about the server related changes that happen when using PaperClip and ImageMagick. I followed a tutorial to learn how to use PaperClip. So when I installed ImageMagick on my laptop Mac OS in order to use the PaperClip gem, things seemed pretty straight forward.
Obviously that means that ImageMagick is installed on my local machine during development, before the push to production on Heroku. Is anything put in my Ruby app for ImageMagick (code, config changes, etc.)? When I push my Ruby app to Heroku, things just seem to work for both ImageMagick and PaperClip.
How and where are the ImageMagick installed components pushed up to Heroku? ImageMagick is not a gem so I am just trying to understand how local development installed software like ImageMagick is transferred to production environments like Heroku.
Is ImageMagick installed, in addition to the PaperClip gem, on the Heroku server (or any server for that matter) when I do the Heroku push? Just trying to understand the use of installed software like ImageMagick vs gems and how things are pushed to production environments and integrated with the app "automagically" working after the push to production.
I want to understand how this works so I can deploy on different server environments (e.g. Rackspace instead of Heroku) and I want to understand what I have to manually install/set-up vs install to get things working. I hope this makes sense.
Any help here is appreciated.
The simple answer (I couldn't bring myself to read your prose) is to realize that Rails runs on Ruby, which means it harnesses the gem system of the language
When you install gems, there are two things you have to consider. Firstly, most gems are "internal" to Ruby only; meaning they will provide functionality for API's or something programmatic; The second bunch of gems work with third party software - such as MYSQL or ImageMagick
When you use a gem which interfaces with other software, that software needs to be installed (so the gem can use it). This is where the problems start to occur for many people using ImageMagick
--
Paperclip
You must remember that Paperclip is not dependent on ImageMagick to run
From the Paperclip github repo:
Paperclip is intended as an easy file attachment library for Active
Record. The intent behind it was to keep setup as easy as possible and
to treat files as much like other attributes as possible. This means
they aren't saved to their final locations on disk, nor are they
deleted if set to nil, until ActiveRecord::Base#save is called. It
manages validations based on size and presence, if required. It can
transform its assigned image into thumbnails if needed, and the
prerequisites are as simple as installing ImageMagick (which, for most
modern Unix-based systems, is as easy as installing the right
packages). Attached files are saved to the filesystem and referenced
in the browser by an easily understandable specification, which has
sensible and useful defaults.
Paperclip can work exclusive to ImageMagick to manage the uploaded images. ImageMagick is an "optional extra", allowing you to crop / edit images on the fly. Like ffmpeg (the video equivalent to ImageMagick), you can run Paperclip on its own
If you want to crop images etc - you'll have to install the library files for ImageMagick on your system. This is simple on Linux, much trickier on Windows
--
Heroku
We're very fortunate in that Heroku is designed to give RoR a stable environment to run with. That said, Heroku does this by providing as much functionality as possible - including the ability to install ImageMagick on the system
Heroku runs linux on Amazon's AWS infrastructure. This means it's relatively simple to use ImageMagick with it - you just need to add it to your gemfile & Heroku will handle the rest
Take a look on the Gemfile located at the root of your Rails application. In there you should have all the Gems used by your application. This file is used by bundler Gem; when you want to deploy the application on a new machine, you don't have to install Gems one-by-one. Just run bundle install and the bundler take care of the Gems.
In Heroku, this is automatized. After git push to heroku, it is doing necessary steps, like bundle install, rake db:migrate, etc.
Please note there is an additional file, Gemfile.lock, contains Gems with versions. This is to ensure that bundler on a new system will install the Gems with the same version as yours.
I have a production app using passenger, nginx, and capistrano. I set it up without RVM (running ruby installed directly to the OS on Ubuntu without a version manager), but would like to switch over to using RVM so that I can upgrade ruby when I need to.
What steps do I need to take to install RVM and configure passenger/nginx/capistrano to use it?
The key here is that I already have the server running, and the downtime needs to be minimal / overnight since the app is being used in a production setting every day. I can't afford to mess up and have the app down for too long.
My best guess is that I'm going to need to modify my nginx config (sudo nano /opt/nginx/conf/nginx.conf) - and edit these lines: (?)
http {
passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19;
passenger_ruby /usr/local/bin/ruby;
Follow instruction on rvm.io to install rvm. However, you are strongly advised not to use it in production. A production setup should follow KISS principle. Every additional piece of software you install, will add a little bit of complexity to the setup. Given that all rvm does is to provide a set of handy commands to install ruby and change PATH variable, it is not an essential tool on production setup.
If all you need is ability to install new versions of ruby without messing things up, use ruby-install. This makes it easy to install ruby, but will not manipulate environment settings (such as PATH).
As you mentioned above, you are right, you should just change the pointer to ruby executable in nginx configuration to switch ruby version. In production mode, this does not stop/interrupt your running rails application until you restart nginx. So it is safe to install a new version of ruby in another folder (such as /usr/local/rubies/ruby-193-p448/ or /usr/local/rubies/ruby-200-p0/), change passenger_ruby in nginx settings to point to the new ruby, then restart nginx.
Also note that from Passenger 4.0.x onwards, you can use multiple versions of ruby with a single nginx/passenger combination, one to run passenger and another to your rails application using the passenger_ruby directive in http block and/or server block of nginx configuration.
I followed all of the directions and this is the result.
I'm in the process of creating the .rvmrc file at my application root path, as well as the setup_load_paths.rb file in my /config folder as described here. I did all that, and then I realized my computer is using ruby 1.9.3p194. While the EC instances is using 1.9.3p286. So I'm in the process of matching them up and re-creating the .rvmrc file.
While doing that, I noticed that the beanstalk ec2 server doesn't even have rails installed. I should be able to type rails --version I assume and see the version like I can on my computer and with ruby --version on the server. So I'm installing RVM, with and rails (as I've done in the past) on my new beanstalk ec2 server. But in general, it seems this all defeats the purpose. It's supposed to be somewhat automatic. Installing rails definitely doesn't sound right. Was it installed another way on the server?
Any advice on how to get the new beanstalk support for ROR working? What am I doing wrong?
From the error in your passenger exception it looks like Bundler was unable to locate the Ascii85 gem in your remote sources. Your remote source should be listed in your Gemfile at the top line in the form:
source :rubygems
If this is not working, try specifying the source explicitly in the form:
source 'http://rubygems.org'
Note that you should not be doing anything special for RVM/Passenger integration in a deploy. In fact, any extra specialized integration may actually cause problems with Elastic Beanstalk if any platform details change. You should be building your application using standard Rails conventions.
As far as rails -v failing: Rails is brought in via your Gemfile, which relies on bundle install succeeding. Your passenger error shows that Bundler failed to resolve your dependencies against your remote sources, which likely means that Rails was also not installed. In other words, Rails will only be available if the bundle installation succeeds.
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.