Halaman

Tampilkan postingan dengan label linode. Tampilkan semua postingan
Tampilkan postingan dengan label linode. Tampilkan semua postingan

Rabu, 24 Oktober 2012

Rails setup in linode

  1. Login to linode
  2. choose linux distribution (ubuntu)
  3. allocate disk space and swap
  4. boot
  5. remote access using ssh
  6. apt-get update
    apt-get upgrade --show-upgraded
  7. set hostname:
    echo "ayahirano" > /etc/hostname
    hostname -F /etc/hostname
  8. nano /etc/hosts
    127.0.0.1 localhost.localdomain localhost
    12.34.56.78 ayahirano.invalid  hirano
    2600:3c01::a123:b456:c789:d012 ayahirano.invalid hirano
  9. set timezone to UTC:
    dpkg-reconfigure tzdata
  10. install required libs:
    apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev libxslt1-dev libcurl4-openssl-dev apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev git-core
  11. install require lib for postgresql (optional):
    apt-get install postgresql postgresql-contrib libpq-dev
  12. create new user:
    adduser example_user
    usermod -a -G sudo example_user
  13. logout and relogin user the new user
  14. disable root login:
    sudo nano /etc/ssh/sshd_config
    PermitRootLogin no
  15. setup postgresql (optional):
    sudo -u postgres createuser --superuser example
    sudo -u postgres psql postgres
    \password example
    \q
    sudo nano /etc/postgresql/8.4/main/postgresql.conf:
    listen_addresses = 'localhost'
    sudo nano /etc/postgresql/8.4/main/pg_hba.conf:
    local       all        all                      md5
    sudo /etc/init.d/postgresql start
  16. install rvm:
    \curl -L https://get.rvm.io | bash -s stable
    source /home/example_user/.rvm/scripts/rvm
  17. install ruby:
    rvm install ruby
  18. disable gem documentation installation:
    nano ~/.gemrc
    gem: --no-ri --no-rdoc
  19. install passenger:
    gem install passenger
    rvmsudo passenger-install-apache2-module
  20. get your app to /var/www/example
  21. disable default virtual host:
    sudo a2dissite default
  22. create new virtual host config:
    sudo nano /etc/apache2/sites-available/example
    <VirtualHost *:80>
      ServerName ayahirano.invalid
      ServerAlias *.ayahirano.invalid
      RailsEnv production
      DocumentRoot /var/www/example/public

      <Directory /var/www/
    example/public>
        AllowOverride all
        # MultiViews must be turned off.
        Options -MultiViews
      </Directory>
    </VirtualHost>
  23. enable it:
    sudo a2ensite example
  24. edit apache configuration file:
    sudo nano /etc/apache2/mods-available/passenger.load
    LoadModule passenger_module /home/rails/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
    sudo nano /etc/apache2/mods-available/passenger.conf
    PassengerRoot /home/rails/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17
    PassengerRuby /home/rails/.rvm/wrappers/ruby-1.9.3-p286/ruby
  25. enable passenger module:
    sudo a2enmod passenger
  26. restart apache:
    sudo service apache2 restart

Extras

Installing nodejs for js runtime (needed by assets precompile):


https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Creating deploy script

  1. cd $HOME
  2. nano deploy.sh
  3. #!/bin/sh
    sudo echo -n "precompile assets? (y or n) : "
    read precompile
    echo -n "bundle install? (y or n) : "
    read bundler
    cd /var/www/example
    git pull
    if [ $bundler = y -o $bundler = Y -o $bundler = yes -o $bundler = Yes -o $bundler = YES ]; then
      bundle install --without development test
    fi
    if [ $precompile = y -o $precompile = Y -o $precompile = yes -o $precompile = Yes -o $precompile = YES ]; then
      bundle exec rake assets:precompile RAILS_ENV=production
    fi
    rake db:migrate RAILS_ENV=production
    # any other thing you do when deploying...
    sudo service apache2 restart
  4. chmod 700 deploy.sh
  5. Done.. To run use: ./deploy.sh