Skip to content

Instantly share code, notes, and snippets.

@huobazi
Created June 15, 2011 06:14

Revisions

  1. @virtualstaticvoid virtualstaticvoid created this gist Jun 13, 2011.
    97 changes: 97 additions & 0 deletions setup.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,97 @@
    #!/bin/bash

    # install dependencies
    apt-get install openssh-server curl git-core
    apt-get install build-essential bison 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

    # install RVM
    bash < <(curl -sk https://rvm.beginrescueend.com/install/rvm)

    ### as per RVM instructions
    nano ~/.bashrc
    #
    # comment out:
    # [ -z "$PS1" ] && return
    #
    # add:
    # if [[ -n "$PS1" ]] ; then
    # ...
    # fi
    #
    # add to EOF:
    # [[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm" # This loads RVM into a shell session.
    #
    ###

    # install ruby 1.9.2 p180 and set as default
    rvm install 1.9.2
    rvm use 1.9.2 --default

    # install nginx + passenger
    rvm gem install passenger
    apt-get install libcurl4-openssl-dev
    passenger-install-nginx-module

    # install nginx as a service
    # cp nginx to /etc/init.d/
    curl -o /etc/init.d/nginx -sk https://gist.github.com/raw/1023883/98dd8ce9f8965dfece7de1c3ade6c775eae83c0e/init_d_nginx
    chmod +x /etc/init.d/nginx
    /usr/sbin/update-rc.d -f nginx defaults

    ##
    # configure nginx
    nano /opt/nginx/conf/nginx.conf
    #
    # add
    # user www-data;
    # worker_processes 4;
    #
    # include /opt/nginx/conf/sites-enabled/*;
    ##

    mkdir /opt/nginx/conf/sites-enabled
    mkdir /opt/nginx/conf/sites-available

    # create nginx configuration files in /opt/nginx/conf/sites-available as needed

    # link into sites-enabled (replace mysite with desired website name)
    ln -s /opt/nginx/conf/sites-available/mysite.com /opt/nginx/conf/sites-enabled/mysite.com

    # install postgresql 9.0
    apt-get install python-software-properties
    add-apt-repository ppa:pitti/postgresql
    apt-get update
    apt-get install postgresql-9.0 libpq-dev
    passwd postgres
    # supply password x2

    su -l postgres
    # psql
    #>> ALTER USER postgres WITH PASSWORD 'sekret';
    #>> CREATE ROLE mysite LOGIN CREATEDB;
    #>> \q

    ##
    nano /etc/postgresql/9.0/main/pg_hba.conf
    # locate 'local all all ident' and change to 'local all all md5'
    #
    ##

    # restart pg
    /etc/init.d/postgresql restart

    # install gem dependencies
    rvm gem install bundler rails pg

    # create location for website files
    mkdir /var/www
    chown www-data /var/www

    # copy rails app to /var/www/mysite
    # [fix up permissions `chown www-data /var/www/mysite -R`]

    #
    # cd into rails app /var/www/mysite
    # bundle exec rake db:create db:migrate db:seed RAILS_ENV="production"
    #