Deploying Rails on Slicehost

Embed Size (px)

Citation preview

  • 8/14/2019 Deploying Rails on Slicehost

    1/56

    Apologies

  • 8/14/2019 Deploying Rails on Slicehost

    2/56

  • 8/14/2019 Deploying Rails on Slicehost

    3/56

    I work here.

  • 8/14/2019 Deploying Rails on Slicehost

    4/56

    Deploying Rails Applicationson a Slicehost VPS

    Jared KuoltSuperJared.com

  • 8/14/2019 Deploying Rails on Slicehost

    5/56

    What is a VPS?

  • 8/14/2019 Deploying Rails on Slicehost

    6/56

    What is a VPS?(We call them Slices)

  • 8/14/2019 Deploying Rails on Slicehost

    7/56

    According to Wikipedia

    A virtual private server is a method ofpartitioning a physical server computer into multiple

    servers that each has the appearance and capabilitiesof running on its own dedicated machine. Each virtualserver can run its own full-fledged operating system,and each server can be independently rebooted.

  • 8/14/2019 Deploying Rails on Slicehost

    8/56

    According to Jared

    A virtual private server is a magic box that

    places power in the hands of the developer, assumingknowledge of sophisticated spells like ssh, grep, andthe all-powerful magic missile.

  • 8/14/2019 Deploying Rails on Slicehost

    9/56

  • 8/14/2019 Deploying Rails on Slicehost

    10/56

    But seriously folks...

  • 8/14/2019 Deploying Rails on Slicehost

    11/56

    +

  • 8/14/2019 Deploying Rails on Slicehost

    12/56

  • 8/14/2019 Deploying Rails on Slicehost

    13/56

    Who needs a VPS?

  • 8/14/2019 Deploying Rails on Slicehost

    14/56

  • 8/14/2019 Deploying Rails on Slicehost

    15/56

    PSYCH!

  • 8/14/2019 Deploying Rails on Slicehost

    16/56

    No way!

    Its for real, true, honest-to-goodness, actual, nonfictional,real-life...

  • 8/14/2019 Deploying Rails on Slicehost

    17/56

  • 8/14/2019 Deploying Rails on Slicehost

    18/56

    Good for...

  • 8/14/2019 Deploying Rails on Slicehost

    19/56

  • 8/14/2019 Deploying Rails on Slicehost

    20/56

    Rails

    Camping

    Merb

    et cetera

  • 8/14/2019 Deploying Rails on Slicehost

    21/56

  • 8/14/2019 Deploying Rails on Slicehost

    22/56

    Django

    TurboGears

    Pylons

    etc cetera

  • 8/14/2019 Deploying Rails on Slicehost

    23/56

    Anything?

  • 8/14/2019 Deploying Rails on Slicehost

    24/56

    Not quite.

  • 8/14/2019 Deploying Rails on Slicehost

    25/56

  • 8/14/2019 Deploying Rails on Slicehost

    26/56

    Installation

  • 8/14/2019 Deploying Rails on Slicehost

    27/56

    Install PrerequisiteSoftware

  • 8/14/2019 Deploying Rails on Slicehost

    28/56

    Apt-get?

  • 8/14/2019 Deploying Rails on Slicehost

    29/56

    $ sudo apt-get install ruby mysql-server

    rubygems ruby1.8-dev build-essentiallibmysql-ruby irb nginx subversion

  • 8/14/2019 Deploying Rails on Slicehost

    30/56

    $ sudo gem update$ sudo gem update --system

    * Note: gem error: /usr/bin/gem:23:uninitialized constant Gem::GemRunner

    (NameError)

  • 8/14/2019 Deploying Rails on Slicehost

    31/56

    $ sudo gem update$ sudo gem update --system

    * Note: gem error: /usr/bin/gem:23:uninitialized constant Gem::GemRunner

    (NameError)

    FIX: add "require 'rubygems/gem_runner'"after "require 'rubygems'" in /usr/bin/gem

  • 8/14/2019 Deploying Rails on Slicehost

    32/56

    $ sudo gem install rails$ sudo gem install mongrel_cluster

  • 8/14/2019 Deploying Rails on Slicehost

    33/56

    Create Database

  • 8/14/2019 Deploying Rails on Slicehost

    34/56

    $ mysql -u root -p> create database myapp;

    > GRANT ALL ON myapp.*TO 'myuser'@'localhost'

    IDENTIFIED BY 'mypassword';

  • 8/14/2019 Deploying Rails on Slicehost

    35/56

    Create Repository

  • 8/14/2019 Deploying Rails on Slicehost

    36/56

    $ svnadmin create repository/

  • 8/14/2019 Deploying Rails on Slicehost

    37/56

    Import Project

  • 8/14/2019 Deploying Rails on Slicehost

    38/56

    Import Project(from your local machine)

  • 8/14/2019 Deploying Rails on Slicehost

    39/56

    $ svn import myapp \svn+ssh://example.com/home/jared/repository/myapp \-m 'Initial import'

    $ mv myapp myapp-old$ svn co svn+ssh://example.com/home/jared/repository/myapp

  • 8/14/2019 Deploying Rails on Slicehost

    40/56

    Setup Capistrano

  • 8/14/2019 Deploying Rails on Slicehost

    41/56

    $ capify .$ mongrel_rails cluster::configure -e production -p 3000 -a127.0.0.1 -N 3 -c /var/www/myapp/current

    $ svn add Capfile config/mongrel_cluster.yml config/deploy.rb$ svn ci -m 'Adding Mongrel cluster and Capistrano information'$ cap deploy:setup$ cap deploy:cold

  • 8/14/2019 Deploying Rails on Slicehost

    42/56

    http://example.com:3000

    http://example.com:3000/http://example.com:3000/
  • 8/14/2019 Deploying Rails on Slicehost

    43/56

    Surviving a Reboot

  • 8/14/2019 Deploying Rails on Slicehost

    44/56

    $ crontab -e

    @reboot mongrel_rails cluster::start -C \/var/www/myapp/current/config/mongrel_cluster.yml

  • 8/14/2019 Deploying Rails on Slicehost

    45/56

    What about port 80?

  • 8/14/2019 Deploying Rails on Slicehost

    46/56

    Nginx?

  • 8/14/2019 Deploying Rails on Slicehost

    47/56

    Nginx?(Its pronounced engine-x)

  • 8/14/2019 Deploying Rails on Slicehost

    48/56

  • 8/14/2019 Deploying Rails on Slicehost

    49/56

  • 8/14/2019 Deploying Rails on Slicehost

    50/56

  • 8/14/2019 Deploying Rails on Slicehost

    51/56

    upstream mongrel {server 127.0.0.1:3000;server 127.0.0.1:3001;server 127.0.0.1:3002;

    }

    server {listen 80;server_name .example.com;root /var/www/myapp/current/public;

    location / {if (-f $request_filename/index.html) {

    rewrite (.*) $1/index.html break;}

    if (!-f $request_filename) {proxy_pass http://mongrel;

    }}

    }

    http://mongrel/http://mongrel/
  • 8/14/2019 Deploying Rails on Slicehost

    52/56

    http://example.com/

    http://example.com:3000/http://example.com:3000/
  • 8/14/2019 Deploying Rails on Slicehost

    53/56

    What now?

  • 8/14/2019 Deploying Rails on Slicehost

    54/56

    # Make some changes

    $ svn ci$ cap deploy

    # Lather, rinse repeat

  • 8/14/2019 Deploying Rails on Slicehost

    55/56

    http://articles.slicehost.com

    http://articles.slicehost.com/http://articles.slicehost.com/
  • 8/14/2019 Deploying Rails on Slicehost

    56/56

    Fin