Including Rails, Passenger, RVM, Ruby 1.9.3, SSH keys, Postgres and a test app
- 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
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
On server (via SSH)
-
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
-
Install system wide RVM
sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
-
Load rvm into current shell session (tell your computer that it knows about RVM)
source /etc/profile.d/rvm.sh
-
Create user and add to rvm group (use either your name or the project name for login)
sudo adduser LOGIN rvm
-
Install ruby 1.9.3 with rvm
rvm install 1.9.3
-
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
-
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
-
Set 1.9.3 as default ruby (and gemset)
rvm use 1.9.3 --default
-
Install passenger and apache module
gem install passenger passenger-install-apache2-module
-
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
-
Configure postgres server (create user account for your login)
sudo -u postgres createuser --superuser LOGIN sudo -u postgres psql \password LOGIN \q
-
Install rails!
gem install rails
Follow a similar process to deploy your own app!
-
Create app
cd ~ # go to home directory rails new testapp # make new rails app cd testapp # enter rails app directory
-
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
-
Scaffold a model and migrate the database
rails g scaffold trinkets rake db:migrate
-
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
-
Add to hosts file on local machine (Google for tutorials)
SERVER_ADDRESS testapp.com
-
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!
When the above works for your own app, you need to set up the following so the internet can use your site!
-
Adjust dns at registrar
set A record to SERVER_ADDRESS add CNAME for "www" to "yourdomain.com"
You could also totally make this a script, by the way.