A guide to setting up a Ruby on Rails production environment on ubuntu 14.04 Trusty Tahr. Since we setup ubuntu for our development environment, we also want to use it in production. Using an LTS version of ubuntu in production allows you to continue receiving security updates.
A guide to setting up a Ruby on Rails production environment on ubuntu 14.04 Trusty Tahr. Since we setup ubuntu for our development environment, we also want to use it in production. Using an LTS version of ubuntu in production allows you to continue receiving security updates.
A guide to setting up a Ruby on Rails production environment on ubuntu 14.04 Trusty Tahr. Since we setup ubuntu for our development environment, we also want to use it in production. Using an LTS version of ubuntu in production allows you to continue receiving security updates.
A guide to setting up a Ruby on Rails production environment on ubuntu 14.04 Trusty Tahr. Since we setup ubuntu for our development environment, we also want to use it in production. Using an LTS version of ubuntu in production allows you to continue receiving security updates.
https://gorails.com/deploy/ubuntu/14.04 1/25 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr A guide to setting up a Ruby on Rails production environment Overview This will take about 45 minutes. We will be setting up a Ruby on Rails production environment on Ubuntu 14.04 LTS Trusty Tahr. Since we setup Ubuntu for our development environment, we also want to use it in production. This keeps your application running consistently between development and production. We're using an LTS version of Ubuntu in production because it is supported for several years where a normal version of Ubuntu isn't. Using Ubuntu LTS in production allows you to continue receiving security updates which is important for your production server(s). We're going to be setting up a Droplet on Digital Ocean (https://www.digitalocean.com/?refcode=87fcb9dab7a3) for our server. It costs $5/mo and is a great place to host your applications. Creating A Virtual Private Server You can use any cloud server hosting company you choose for your Rails application. I've had excellent experience with Digital Ocean (https://www.digitalocean.com/? refcode=87fcb9dab7a3) and Linode (https://www.linode.com/? r=a02b271802c33ff2f38b3d5335089d76648ca6c2) with the servers I have used. If you're looking for alternatives outside the US or otherwise, just google "VPS hosting". A VPS is a virtual private server. It's just like a server you setup at home, only virtualize and running with a suite of other servers in a datacenter. Ubuntu 14.04 (/deploy/ubuntu/14.04) Ubuntu 12.04 (/deploy/ubuntu/12.04) 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 2/25 Since we're using Digital Ocean (https://www.digitalocean.com/? refcode=87fcb9dab7a3) for our cloud server, the first thing we're going to do is configure a new one. I'm going with the Droplet with 1GB of RAM. You can setup whichever size server you prefer, keep in mind that if you choose a 512MB server you may run into some slowness with a low amount of RAM. (http://cl.ly/RGNu/Screen%20Shot%202013-09-08%20at%206.00.59%20PM.png) The next step is to choose your location. Choose one close to you so that you can have better connection speeds. (http://cl.ly/RFcK/Screen%20Shot%202013-09-08%20at%206.02.14%20PM.png) Last, but not least we need to choose which OS to use. We're going to be using Ubuntu 14.04 LTS x64. Your application may require a different OS or version, but if you're not sure this is generally what you should use. 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 3/25 (http://cl.ly/VRNn/Screen%20Shot%202014-05-08%20at%205.54.39%20PM.png) Once Digital Ocean has configured your server, check your email to get your password for the new cloud server. (http://cl.ly/RGaf/Screen%20Shot%202013-09-08%20at%206.43.18%20PM.png) You should follow the instructions in the email to login via SSH for the very first time and verify it is working. The first thing we will do on our new server is create the user account we'll be using to run our applications and work from there. sudo adduser deploy sudo adduser deploy sudo su deploy 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 4/25 Before we move forward is that we're going to setup SSH to authenticate via keys instead of having to use a password to login. It's more secure and will save you time in the long run. We're going to use ssh-copy-id to do this. If you're on OSX you may need to run brew install ssh-copy-id but if you're following this tutorial on Linux desktop, you should already have it. Once you've got ssh-copy-id installed, run the following and replace IPADDRESS with the one for your server: Make sure you run ssh-copy-id on your computer, and NOT the server. ssh-copy-id deploy@IPADDRESS Now when you run ssh deploy@IPADDRESS you will be logged in automatically. Go ahead and SSH again and verify that it doesn't ask for your password before moving onto the next step. For the rest of this tutorial, make sure you are logged in as the deploy user on the server! Installing Ruby Choose the version of Ruby you want to install: 2.1.2 (Recommended) The first step is to install some dependencies for Ruby. sudo apt-get update sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadl ine-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-open ssl-dev python-software-properties Next we're going to be installing Ruby using one of three methods. Each have their own benefits, most people prefer using rbenv these days, but if you're familiar with rvm you can follow those steps as well. I've included instructions for installing from source as well, but in general, you'll want to choose either rbenv or rvm. Choose one method. Some of these conflict with each other, so choose the one that 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 5/25 sounds the most interesting to you, or go with my suggestion, rbenv. Installing with rbenv is a simple two step process. First you install rbenv , and then ruby-build : cd git clone git://github.com/sstephenson/rbenv.git .rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec $SHELL git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL rbenv install 2.1.2 rbenv global 2.1.2 ruby -v The last step is to tell Rubygems not to install the documentation for each package locally echo "gem: --no-ri --no-rdoc" > ~/.gemrc Installing Nginx Phusion is the company that develops Passenger and they recently put out an official Ubuntu package that ships with Nginx and Passenger pre-installed. We'll be using that to setup our production server because it's very easy to setup. Using rbenv Using rvm From source 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 6/25 # Install Phusion's PGP key to verify packages gpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7 gpg --armor --export 561F9B9CAC40B2F7 | sudo apt-key add - # Add HTTPS support to APT sudo apt-get install apt-transport-https # Add the passenger repository sudo sh -c "echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger tru sty main' >> /etc/apt/sources.list.d/passenger.list" sudo chown root: /etc/apt/sources.list.d/passenger.list sudo chmod 600 /etc/apt/sources.list.d/passenger.list sudo apt-get update # Install nginx and passenger sudo apt-get install nginx-full passenger So now we have Nginx and passenger installed. We can manage the Nginx webserver by using the service command: sudo service nginx start Open up the server's IP address in your browser to make sure that nginx is up and running. The service command also provides some other methods such as restart and stop that allow you to easily restart and stop your webserver. Next, we need to update the Nginx configuration to point Passenger to the version of Ruby that we're using. You'll want to open up /etc/nginx/nginx.conf in your favorite editor, find the following lines, and uncomment them: ## # Phusion Passenger ## # Uncomment it if you installed ruby-passenger or ruby-passenger-enterprise ## passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; passenger_ruby /usr/bin/ruby; # passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number # passenger_ruby /home/deploy/.rbenv/shims/ruby; # If you use rbenv The passenger_ruby is the important line here. We want this to match the output of which ruby in terminal. This is probably correct already if you installed Ruby from source. If you used rbenv, it would look something like this /home/deploy/.rbenv/shims/ruby . 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 7/25 Once you've changed passenger_ruby to use the right version Ruby, you can run sudo service nginx restart to restart Nginx with the new Passenger configuration. Now that we've restarted Nginx, the Rails application will be served up using the deploy user just how we want. In the Capistrano section we will talk about configuring Nginx to serve up your Rails application. MySQL and PostgreSQL Database Setup Setting up your production database is pretty easy. Make sure to keep in mind that you should use a different password for your production databases. Depending on what database you want to use, follow the steps related to the database: Installing MySQL All you need to do in order to install MySQL is to run the following command: sudo apt-get install mysql-server mysql-client libmysqlclient-dev You can use the root user and password set during installation for your database or you can add a new user (https://www.digitalocean.com/community/articles/how-to- create-a-new-user-and-grant-permissions-in-mysql) to MySQL. Installing PostgreSQL Postgres 9.3 is available in the Ubuntu repositories and we can install it like so: sudo apt-get install postgresql postgresql-contrib libpq-dev Next we need to setup our postgres user: sudo su - postgres createuser --pwprompt exit The password you type in here will be the one to put in your my_app/current/config/database.yml later when you deploy your app for the first time. 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 8/25 Capistrano Setup The fancy new verison of Capistrano 3.0 just shipped and we're going to be using it to deploy this application. The first step is to add Capistrano to your Gemfile : gem 'capistrano', '~> 3.1.0' gem 'capistrano-bundler', '~> 1.1.2' gem 'capistrano-rails', '~> 1.1.1' # Add this if you're using rbenv # gem 'capistrano-rbenv', github: "capistrano/rbenv" # Add this if you're using rvm # gem 'capistrano-rvm', github: "capistrano/rvm" Once these are added, run bundle --binstubs and then cap install STAGES=production to generate your capistrano configuration. Next we need to make some additions to our Capfile to include bundler, rails, and rbenv/rvm (if you're using them). Edit your Capfile and add these lines: require 'capistrano/bundler' require 'capistrano/rails' # If you are using rbenv add these lines: # require 'capistrano/rbenv' # set :rbenv_type, :user # or :system, depends on your rbenv setup # set :rbenv_ruby, '2.0.0-p451' # If you are using rvm add these lines: # require 'capistrano/rvm' # set :rvm_type, :user # set :rvm_ruby_version, '2.0.0-p451' After we've got Capistrano installed, we can configure the config/deploy.rb to setup our general configuration for our app. Edit that file and make it like the following replacing "myapp" with the name of your application and git repository: 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 9/25 set :application, 'myapp' set :repo_url, 'git@github.com:excid3/myapp.git' set :deploy_to, '/home/deploy/myapp' set :linked_files, %w{config/database.yml} set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/ system} namespace :deploy do desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do execute :touch, release_path.join('tmp/restart.txt') end end after :publishing, 'deploy:restart' after :finishing, 'deploy:cleanup' end Now we need to open up our config/deploy/production.rb file to set the server IP address that we want to deploy to: set :stage, :production # Replace 127.0.0.1 with your server's IP address! server '127.0.0.1', user: 'deploy', roles: %w{web app} If you have any trouble with Capistrano or the extensions for it, check out Capistrano's Github page (https://github.com/capistrano/). Final Steps Thankfully there aren't a whole lot of things to do left! Adding The Nginx Host In order to get Nginx to respond with the Rails app, we need to modify it's sites- enabled. Open up /etc/nginx/sites-enabled/default in your text editor and we will replace the file's contents with the following: 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 10/25 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name mydomain.com; passenger_enabled on; rails_env production; root /home/deploy/myapp/current/public; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } This is our Nginx configuration for a server listening on port 80. You need to change the server_name values to match the domain you want to use and in root replace "myapp" with the name of your application. Connecting The Database You can run cap production deploy to deploy your application. The file config/database.yml needs to be updated for the production database server username, password, and host. You can set host to "localhost" and you will have to create a database on the server with the same name. Capistrano won't create it for you because it's something that should really only happen once. After deploying you can set create it by SSHing in and running RAILS_ENV=production bundle exec rake db:create in your app's /home/deploy/myapp/current directory ( just change "myapp" to match the name of your app). Something you should consider is only storing the database credentials on the server and having Capistrano symlink the database.yml file so that it doesn't have to be stored in git. This is especially important when you have a public git repository and don't want to publish your database credentials. Restarting The Site One last thing you should know is that restarting just the Rails application with Passenger is very easy. If you ssh into the server, you can run touch myapp/current/tmp/restart.txt and Passenger will restart the application for you. It monitors the file's timestamp to determine if it should restart the app. This is helpful when you want to restart the app manually without deploying it. 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 11/25 Tweet 9 0 10 Share Conclusion And there you have it, a very long-winded explanation of all the different things you need to do while setting up an application to be deployed. There is a lot of system administration pieces that can expand upon this, but that's for another time. Please let me know if you have any questions, comments, or suggestions! We're sharing everything we know about how to write great quality code Join the GoRails mailing list to learn more about what great code looks like, why it is great, and how you can write great code yourself that you will enjoy working with. Email Address Send Me Lessons On Rails 99 Comments GoRails Login Sort by Best Share Join the discussion Daniel Baldwin 24 days ago Hi, thanks for the tut, it seems like a very concise and informative resource. Favorite 7 Share First Name Last Name 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 12/25 Reply see more I seem to have hit an issue though, when running: cap production deploy I get an error: ERROR linked file /home/deploy/my_actual_app_name/shared/config/database.yml does not exist on my.server.ip.address cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host my.server.ip.address: exit The backtrace is pretty unhelpful but the tasks: TOP suggests the issue is originating (as expected) from config/deploy.rb Tasks: TOP => deploy:check:linked_files
2 Reply Chris Oliver 24 days ago Mod Daniel Baldwin Hey Daniel, You'll need to manually create a database.yml file on your server. It's trying to link it but it hasn't been created yet. So you can ssh in and edit that file nano /home/deploy/my_actual_app_name/shared/config/database.yml and put in your database config for the server database that you just setup.
1 Reply andre bautista 13 days ago Chris Oliver Hi Chris, I followed these steps in creating a database.yml file in the listed directory and I'm getting the error "rm stdout: Nothing written rm stderr: rm: cannot remove /home/deploy/gymsight/releases/20140630064741/config/database.yml: No such file or directory" Any ideas on how to get past this?
andre bautista 11 days ago andre bautista The repo helped me work through most of the problems. Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 13/25 Reply The repo helped me work through most of the problems. Just need to clarify one thing now. In the database.yml file the username should be "postgres" and the password is the password we entered when we created "postgres"? I'm able to sign into the user fine if I "su postgres" but when I use those credentials in the database.yml file to create a DB, after signing back into deploy, I get the error FATAL: password authentication failed for user "postgres".
1 Reply Chris Oliver 11 days ago Mod andre bautista I guess, just double check that you've got it in the right format then. Can't think of anything else that would be wrong. You're pretty close now!
Reply andre bautista 11 days ago Chris Oliver sigh...Heroku won this battle
Reply Chris Oliver 11 days ago Mod andre bautista Dang! : To be fair, Heroku's simplicity is pretty darn impressive and I don't blame you. If you ever do need to get your site running on a VPS, shoot me an email and we can do a short one-on-one gig and I can probably get you squared away.
Reply Chris Oliver 12 days ago Mod andre bautista Hmm, that's odd. It shouldn't be trying to remove the file. Can you send over some more of your logs in a github gist?
Reply andre bautista 12 days ago Chris Oliver https://gist.github.com/andreb... So the error has changed magically, but it appears as though it's trying to access all the branches of my repo even though I'm specifying "set :branch, 'master'" in the deploy file.
Chris Oliver 12 days ago Mod andre bautista That's okay because it is just cloning the repository. It looks like the symlink is crashing possibly because Share Share Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 14/25 Reply looks like the symlink is crashing possibly because /home/deploy/gymsight/shared/config/database.yml doesn't exist. Have you double checked that file exists?
Reply andre bautista 12 days ago Chris Oliver Just checked, file is there. I also edited the gist to show my latest error message.
Reply Chris Oliver 12 days ago Mod andre bautista Looks like you've already got a database.yml in your repo. Either remove the symlink on deploy and add your credentials to that file, or remove the file from git so that it can symlink on deploy.
Reply andre bautista 12 days ago Chris Oliver I don't have a database.yml in the remote repo. (https://github.com/andrebautis... ) Here's my deploy.rb file, I think the error might be in the deploy itself, I'm still trying to decipher what all these things mean. https://gist.github.com/andreb...
Reply Chris Oliver 12 days ago Mod andre bautista Interesting, that all looks correct to me.
Reply andre bautista 12 days ago Chris Oliver Do you have a public repository with this kind of set up? It could also be my production.rb file causing issues. https://gist.github.com/andreb...
Reply Chris Oliver 11 days ago Mod andre bautista Here's an example: https://github.com/excid3/anim...
Daniel Baldwin 23 days ago Chris Oliver Thanks Chris. That makes sense now. I assume that there are ways to automate this part of the process but I guess it's also an idea to do it manually for the extra layer of control it grants. I also hit a few other issues after this (and so have yet to actually Share Share Share Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 15/25 Reply deploy) but seem to be making steady progress now. Thanks again.
Reply Chris Oliver 23 days ago Mod Daniel Baldwin Sometimes people keep database.yml in their repository but then your production password is saved in your code repo so a lot of people choose not to do it that way. Let me know if I can help out with any of the other issues!
Reply Daniel Baldwin 19 days ago see more Chris Oliver Thanks again, I managed to get through it soon enough after this issue. My business partner actually decided to use Figaro for exactly that purpose. It means that we can keep the database.yml file in version control whilst keeping the particulars locally secured. The snippet here: https://gist.github.com/patte/... helped somewhat with getting the application.yml file onto the server but I found that because we were using Devise I had to change the line: after "deploy:symlink:release", "figaro:symlink" to before "deploy:compile_assets", "figaro:symlink"
Reply Chris Oliver 19 days ago Mod Daniel Baldwin Awesome stuff. Thanks for sharing Daniel.
Reply Mark Sugan 16 hours ago Hi, thanks for this tutorial, I tried to follow every step, I deployed the app with some fails http://pastebin.com/zgkQXcqE the vps still showing the nginx welcome message, I can't figure out why!
Share Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 16/25 Reply Chris Oliver 6 hours ago Mod Mark Sugan Your deploy was successful. The failures are supposed to happen. Make sure you point nginx to /home/deploy/sample_app/current/ and restart it.
Reply Mark Sugan 6 hours ago Chris Oliver Just checked, default file in /etc/nginx/sites-enabled/ is filled with correct values, it's weird root /home/deploy/sample_app/current/public;
Reply Chris Oliver 5 hours ago Mod Mark Sugan You can check the nginx log then for errors and you should find something there. Could be syntax errors for example.
1 Reply Mark Sugan 5 hours ago Chris Oliver There was no error in syntaxe, but it woked after commenting those lignes: # listen 80 default_server; # listen [::]:80 default_server ipv6only=on;
Reply Felipe Campos Clarke 2 days ago this was very useful for me. Thank you very much for the article!
Reply Deb Lora 15 days ago Hey, thanks a lot for this tutorial. This is one of the most comprehensive one that I've come across thus far! I am running into some trouble however. For some reason, the app that is actually up and running on my server is an older version (from like two months ago) of my application, but the "current" version of the app is my desired up-to- date one. (I see this when I review the code in that directory.) I've specified that the master branch should be deployed, restarted the web and app servers, precompiled assets. But, I still have this older version running. (I am having the same problem this person had http://stackoverflow.com/quest... Does anyone have any ideas as to why this may be the case?
Share Share Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 17/25 Reply Chris Oliver 15 days ago Mod Deb Lora One thing is to check and make sure your config points to the right directory. It definitely has happened to me before, but it is almost always a case of either reading the wrong config or the config pointing to the wrong folder.
Reply Deb Lora 14 days ago Chris Oliver Thank you! I double checked the config. It turned out that the problem was not cap but my own code. For anyone reading this if your site looks like an older version of your site, it might just be that your assets are not loading properly. It turns out that my custom stylesheet was not actually loading, and there was an error in the precompilation of assets because of this. One way to check for that is by (if you're using chrome) go to a page on your app, open the inspect tool (ctrl + i), go to the network tab, refresh your page. Look for any red links (stylesheets or assets that are not loading). This is a problem with your code not capistrano. The code for loading specific stylesheets was working on my local machine, but it didn't work in production. So double check that. :]
1 Reply Chris Oliver 14 days ago Mod Deb Lora Oh! That's an interesting one. It has happened to me before but that definitely is an obscure one. I'm glad you got it figured out!
Chris Sciolla 15 days ago Hi Chris, I've followed this tutorial exactly and I'm getting the following error and can't figure out why. I also have no idea why example.com is there... cap production deploy:check [68f3b617] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p481 ] on ***.***.***.*** [68f3b617] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ] [d8d5b994] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p481 ] on example.com [d8d5b994] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ] [68f3b617] Finished in 1.144 seconds with exit status 1 (failed). Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 18/25 Reply [68f3b617] Finished in 1.144 seconds with exit status 1 (failed). cap aborted! SSHKit::Runner::ExecuteError: Exception while executing on host example.com: No route to host - connect(2) Errno::EHOSTUNREACH: No route to host - connect(2) Tasks: TOP => rbenv:validate Any ideas? Thanks for taking the time to write this up.
Reply Chris Oliver 15 days ago Mod Chris Sciolla Check your config/deploy/production.rb file to make sure it doesn't have example.com in it. I would guess that's where it is coming from. Swap that with your domain or IP and you should be good.
Reply Chris Sciolla 15 days ago Chris Oliver That's the weird thing. I only have the correct IP address in there. do I need to run any commands if I change production.rb? re- commit to github on restart the production server?
Reply Chris Oliver 15 days ago Mod Chris Sciolla Make sure the file is saved, but that's all you should need to do. You can try doing a project wide search in your text editor to find "example.com". That should point you to it.
Reply Chris Sciolla 15 days ago Chris Oliver ughhhhh. can't believe I missed that in production.rb in the roles. sorry for the stupid question...
Reply Chris Oliver 15 days ago Mod Chris Sciolla I've had times where I went through everything and I couldn't find it so I ended up deleting all the files and starting from scratch so I know the feeling well. ;-)
Chris Sciolla 15 days ago Chris Oliver I got the dreaded, We're sorry , but something went wrong and have no idea where to start looking. I got a bunch of fails during the cap build, many similar to: Command: [ -L /home/deploy/*****/releases/20140627215511/tmp/ Share Share Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 19/25 Reply /home/deploy/*****/releases/20140627215511/tmp/ Finished in 0.051 seconds with exit status 1 (failed).
Reply Chris Oliver 15 days ago Mod Chris Sciolla Sometimes having failed commands is good. It occasionally checks to see if it needs to create a directory like this one so it fails because it already exists which is totally okay.
Reply Jakub Kuchar 17 days ago Soon i would like to write a deployment guide for opensource project https://github.com/sharetribe/... from non-server guy perspective. And this guide playing a big role, i hope you wouldn't mind that i will reference it via link?
Reply Chris Oliver 16 days ago Mod Jakub Kuchar I don't mind at all Jakub. Let me know if there's anything I can help with.
Reply Nick DelRossi 19 days ago Thanks for the tutorial. I want to add a helpful tip incase anyone else's Rails app has SSL enabled and is not working. If you have enabled SSL/https on your Rails app, you will need to add another step to this process. I went through this tutorial and was getting ERR_CONNECTION_REFUSED in chrome when I tried to get to my site. I am new to this and it took me hours before I realized what the problem was. If you follow the steps in this article it should fix the issue. https://www.digitalocean.com/c...
Reply Chris Oliver 19 days ago Mod Nick DelRossi Thanks for sharing Nick!
Bhuwan Arora 22 days ago I have managed to go through and run the complete tutorial, but after running touch APP-NAME/current/tmp/restart.txt I only see an nginx welcome page on the server IP. How can I debug the problem. These are my config files config/deploy.rb http://pastebin.com/1SXMDYvS config/deploy/production.rb http://pastebin.com/ZYGejqJF Share Share Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 20/25 Reply /etc/nginx/sites-enabled/default http://pastebin.com/0JNG54KH I also tried with SERVER-IP instead of WEB-ADDRESS in server-name in /etc/nginx/sites-enabled/default Where am I go wrong
Reply Bhuwan Arora 22 days ago Bhuwan Arora Ahh I found out I had created a backup for nginx.conf with the name nginx.conf.backup and that was creating all the problem..
Reply Prasad Saxena 23 days ago Hello Chris, Here is the error I see when I try to run the command bundle --binstubs deploy@sparktransfer:~/AsachTimepass$ bundle --binstubs /home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError) from /home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' from /usr/bin/bundle:7:in `<main>' I am using passenger_ruby /home/deploy/.rbenv/shims/ruby; in the nginx.conf file, but it still doesnt work. Can you help me ?
Reply Guest 23 days ago Where is the Gem File ? Please give me the exact location of the Gemfile. "like /home/rails or /etc/nginx etc." To add the lines : gem 'capistrano', '~> 3.1.0' gem 'capistrano-bundler', '~> 1.1.2' gem 'capistrano-rails', '~> 1.1.1' # Add this if you're using rbenv # gem 'capistrano-rbenv', github: "capistrano/rbenv"
Chris Oliver 22 days ago Mod Guest Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 21/25 Load more comments ALSO ON GORAILS Reply The Gemfile is in the top folder in your Rails application.
Reply Benjamin S 25 days ago see more Awesome tut, thank you very much. I managed to deploy but I have an error "We're sorry, but something went wrong." when i type sudo less /var/log/nginx/error.log i get the following. [ 2014-06-17 04:55:18.8418 903/7f6b1e392700 agents/HelperAgent/RequestHandler.h:2262 ]: [Client 20] Cannot checkout session. Error page: Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2 (Bundler::RubyVersionMismatch) /home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler- 1.6.3/lib/bundler/definition.rb:390:in `validate_ruby!' /home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-1.6.3/lib/bundler.rb:116:in `setup' /home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-
Reply Chris Oliver 25 days ago Mod Benjamin S Double check that you set your nginx passenger_ruby to point to RVM or Rbenv properly and that you set the global ruby version to 2.1.2.
Reply Benjamin S 25 days ago Chris Oliver This is how it looks like. passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; passenger_ruby /home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby; and :~$ which ruby /home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby
WHAT'S THIS? Share Share Share Share 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 22/25 Episodes 3 comments 11 months ago karam keep it up guys! thanks for the help. Setup Ruby on Rails on Ubuntu 14.04 72 comments 6 months ago Mark Railton Thanks Chris, this is just what I was looking for to get my development server up and running. 3: Rails Application Structure 4 comments a month ago DevinHe Thank you for your great introduce.Now i also understand how the Rails works more clearly. Trying Out Bootstrap 3.0 by Chris Oliver 5 comments a year ago codybarr Thanks for this post. Worked like a charm! ALSO ON GORAILS WHAT'S THIS? Subscribe Add Disqus to your site 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 23/25 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 24/25 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails https://gorails.com/deploy/ubuntu/14.04 25/25 Follow @excid3 1,520 followers
Tweet 44 Copyright Chris Oliver (http://excid3.com) 2014. St. Louis Ruby on Rails (/st-louis-ruby-on- rails) | About (/about)