Cloning a Rails App9:51 with Jay McGavren
Now it's time to deploy that app you've been working on in development to the server. The easiest and best way to do that is to clone the source code from version control (e.g. Git).
Run these commands while logged in as the deployment user on your server:
$ echo 'gem: --no-document' >> ~/.gemrc $ git clone firstname.lastname@example.org:treehouse-projects/rails-guestbook.git $ gem install bundler $ cd rails-guestbook $ bundle install $ RAILS_ENV=production bin/rails db:setup
We need to store the Rails secret key as an environment variable. The
rbenv-vars library will let us do so. On your server, run:
$ git clone https://github.com/sstephenson/rbenv-vars.git ~/.rbenv/plugins/rbenv-vars $ bin/rails secret
Copy the secret key it generates, then paste it in place of
<secret_key> in the command below:
$ echo 'SECRET_KEY_BASE=<secret_key>' >> .rbenv-vars
You should be ready to run your app now.
Running the app
Run this command while logged in as the deployment user on your server:
$ RAILS_ENV=production bin/rails server
Finding your server's public IP address
Then, in your browser address bar, you'll need to type an IP address and port number, separated by a colon:
<address>:3000. (The Rails server will be running on port 3000.) For the address portion, you'll need to find the public IP address of your server.
If you're running the server locally as a virtual machine, you'll need to forward traffic from port 3000 on your own computer to port 3000 on the virtual machine. This video includes additional information about forwarding ports in VirtualBox. Then you'll need to connect to your own computer from your browser using the special IP address
If you're running an actual server with a web hosting company, consult their online documentation to learn how to look up your server's IP address. Most hosting companies offer a web-based control panel where you can configure your servers, and the IP address should be listed there.
You need to sign up for Treehouse in order to download course files.Sign up