Skip to content

Instantly share code, notes, and snippets.

@Glench
Forked from jmondo/ubuntu-setup.md
Created April 2, 2012 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glench/2283245 to your computer and use it in GitHub Desktop.
Save Glench/2283245 to your computer and use it in GitHub Desktop.
Setting up Rails server environment on Ubuntu 11.10

Setting up Rails server environment on Ubuntu 11.10

Including Rails, Passenger, RVM, Ruby 1.9.3, SSH keys, Postgres and a test app

Instructions

  • This is tested on a clean install of Ubuntu 11.10 server (with SSH root access), though it should work on whatever install you have now.
  • Replace LOGIN with your ubuntu username
  • Replace SERVER_ADDRESS with the IP address of your server

General Server Setup

Some User Setup

ssh root@SERVER_ADDRESS           # ssh into server
adduser LOGIN                     # create a user
adduser LOGIN admin               # add user to admin group
exit                              # sign out

ssh-copy-id LOGIN@SERVER_ADDRESS  # copy your ssh key to the server (from local computer)
ssh LOGIN@SERVER_ADDRESS          # ssh into server

Environment Setup

On server (via SSH)

  1. Install a bunch of dependencies

     sudo apt-get install curl git-core build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion libcurl4-openssl-dev apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev postgresql
    
  2. Install system wide RVM

     sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
    
  3. Load rvm into current shell session (tell your computer that it knows about RVM)

     source /etc/profile.d/rvm.sh
    
  4. Create user and add to rvm group (use either your name or the project name for login)

     sudo adduser LOGIN rvm
    
  5. Install ruby 1.9.3 with rvm

     rvm install 1.9.3
    
  6. Tell rvm to not generate documentation (saves time)

     sudo nano /etc/gemrc            # open file
     gem: --no-ri --no-rdoc          # add this to contents (paste)
     control-o                       # save
     control-x                       # close nano
    
  7. Tell rvm to ignore project files (since passenger only runs within one gemset)

     echo "rvm_project_rvmrc=0" >> /etc/rvmrc # output to end of file
    
  8. Set 1.9.3 as default ruby (and gemset)

     rvm use 1.9.3 --default
    
  9. Install passenger and apache module

     gem install passenger
     passenger-install-apache2-module
    
  10. Configure apache as instructed

    sudo nano /etc/apache2/conf.d/passenger   # open file
    

    Paste the config given to you by the end of the passenger/apache install

    It looks something like this:

    LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
    PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p125/gems/passenger-3.0.11
    PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p125/ruby
    
  11. Configure postgres server (create user account for your login)

    sudo -u postgres createuser --superuser LOGIN
    sudo -u postgres psql
    \password LOGIN
    \q
    
  12. Install rails!

    gem install rails
    

App Specific Setup

Server Stuff

Follow a similar process to deploy your own app!

  1. Create app

     cd ~                      # go to home directory
     rails new testapp         # make new rails app
     cd testapp                # enter rails app directory
    
  2. Set up database

     nano config/database.yml  # create database config
    

    Paste this and NOTE: password not required because postgres login and ubuntu login are the same

     development:
       adapter: postgresql
       encoding: unicode
       database: test_app_production
       pool: 5
       username: LOGIN
    
  3. Scaffold a model and migrate the database

     rails g scaffold trinkets
     rake db:migrate
    
  4. Tell apache about the site

     sudo nano /etc/apache2/sites-available/testapp
    
     <VirtualHost *:80>
        ServerName testapp.com
        DocumentRoot /home/LOGIN/testapp/public
        <Directory /home/LOGIN/testapp/public>
           AllowOverride all
           Options -MultiViews
        </Directory>
     </VirtualHost>
    
     sudo a2ensite testapp
     sudo /etc/init.d/apache2 restart
    
  5. Add to hosts file on local machine (Google for tutorials)

     SERVER_ADDRESS	testapp.com
    
  6. Test! from local machine (in a browser)

     http://SERVER_ADDRESS/trinkets
    

    You should be able to create, update, add, and destroy trinkets! If so, everything is working! if not, something's wrong.

    When you're done playing with trinkets, follow the app specific setup section again with your own app, instead of a test app!

External Stuff

When the above works for your own app, you need to set up the following so the internet can use your site!

  1. Adjust dns at registrar

     set A record to SERVER_ADDRESS
     add CNAME for "www" to "yourdomain.com"
    
@Glench
Copy link
Author

Glench commented Apr 2, 2012

You could also totally make this a script, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment