All posts tagged Ruby on Rails

Installing OpenVZ and WebVZ in Centos 5.5

OpenVZ is an operating system-level virtualization technology based on the Linux kernel and operating system. OpenVZ allows a physical server to run multiple isolated operating system instances, known as containers, Virtual Private Servers (VPSs), or Virtual Environments (VEs).

Now we’ll try to install OpenVZ in Centos. OpenVS is an operating system-level VPS so you need to install Host Operating System ( if you are using hardware virtualization like Xen or VMware then you don’t have to install an Operating System ).

The first step is that you must install the Centos ( I am using Centos 5.5 ). I won’t explain about how to install it so you must find the tutorial yourself :P

Let’s say you already installed the Centos, next step is updating your yum package manager. Here are the steps :

  • Download the OpenVZ repo from http://download.openvz.org/openvz.repo
  • Put it in /etc/yum.repos.d directory
  • Run the yum update command

Wait until the process is complete, it will downloading all the necessary update package. ( you can find the complete tutorial in OpenVZ Wiki ).

Now we will install the OpenVZ, type this to install the OpenVZ :

yum install ovzkernel vzctl

If the installation running smooth you will have OpenVZ installed, reboot your machine :

reboot

Press any key when the Grub screen is popping out. If it’s installed then you must have 3 kernels. Choose the top kernel ( it’s the OpenVZ kernel, in my machine the name is CentOS ( 2.6.18-194.3.1.el5.028stab069.6 ).

Log in to your machine as usual, now you are running on OpenVZ kernel. The next step is we will install WebVZ ( the OpenVZ management GUI ). The WebVZ, like it’s name, is a web application that runs on Ruby on Rails. So you must have Ruby on Rails in your machine to use the WebVZ.

To help us installing the Ruby on Rails we will use Ruby Works . Ruby Works is one of the CentOS repository that provides with the newest installer of Ruby, Gem and Rails.

Here are the steps :
1.Download the repo file

wget http://rubyworks.rubyforge.org/RubyWorks.repo

2.Put it the file in the /etc/yum.repos.d
3.yum update

yum update

4.Installing the ruby packages

yum install ruby ruby-devel ruby-irb ruby-rdoc ruby-ri

5.Check the installed Ruby using this command ( it should print out the ruby version eg: ruby 1.8.6 )

ruby -v

6.Then download the latest gem at Rubyforge
7.After download the latest gem, extract it, go the folder and run the installer

ruby setup.rb

8.Check if the gem is installed successfully ( it should return the version too )

gem -v

9.Run the gem update to make sure the gem is up to date.

gem update

10.Install the rails

gem install rails -v=2.3.2

11.The WebVZ need sqlite to run, so you must install the sqlite and the gcc compiler

yum install sqlite-devel
yum install gcc make

12.And the last is installing the sqlite for ruby

gem install sqlite3-ruby -v=1.2.5

13.Download the WebVZ installer from it’s website. Extract it and run the application.

cd webvz
ruby script/server

That’s all, then you can access it via web browser http://your-ip:3000. the username is admin and the password is admin123.

Update : ( run the WebVZ as daemon )
to run WebVZ as daemon just go to it’s directory run this command instead of plain “ruby script/server”

ruby script/server &>/dev/null &

and to make it’s run everytime you boot the machine ( put it in rc.local )

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

cd /usr/local/webvz/ && /usr/bin/ruby script/server &>/dev/null &

exit 0

Ruby on Rails in Kubuntu 9.04

Beberapa hari ini gwa disibukkan mencoba menginstall Ruby on Rails ( RoR ). Sebenarnya sudah cukup lama pengen coba-coba Ruby on Rails, tapi sekarang baru ada semangat sama ada waktu buat nyoba-nyoba.

Menginstall Ruby on Rails ini dapat dibilang cukup memakan banyak waktu dikarenakan gwa menghabiskan 1 harian HANYA untuk install Kubuntu doank ( gara2 cd rom yang ga jelas ).

Jadi setelah gwa berhasil menginstall kubuntu ( yang tentu saja gwa selesaikan dalam waktu 1 hari ) gwa mulai menginstall Ruby on Rails. Mungkin masih pada bingung sebenarnya Ruby on Rails itu apaan. Ruby on Rails itu adalah sebuah framework untuk pembuatan website yang dibuat dengan menggunakan bahasa Ruby.

Apa istimewanya ? Kok semua sekarang pada ngomong Ruby on Rails mulu ? Kalau yang setau gwa Ruby on Rails adalah framework yang pertama kali menerapkan konsep MVC ( Model – View – Controller ) yang banyak diadopsi oleh framework-framework lain ( CakePHP, CI, Symfony, Spring, dll ). Selain itu Twitter juga menggunakan Ruby on Rails sebagai platform utamanya ( walaupun ada performance issue ).

Yah jadi langsung aja kita mulai step-step menginstall Ruby on Rails. Langkah-langkahnya sebenarnya terbagi dalam beberapa bagian yaitu :

  1. Menginstall package yang dibutuhkan oleh Ruby on Rails
  2. Menginstall database server yang mau digunakan
  3. Menginstall Ruby, Rubygem, dan yang terakhir Rails

Kelihatannya gampang menginstall Ruby on Rails, tetapi karena banyaknya dependency terhadap package membuat kita harus sering compile ulang Ruby ( mungkin yang pakai apt-get lebih gampang, tetapi sekarang kita akan mencoba install from source ).

Berikut biodata dari Ruby yang akan kita install :

  1. ruby-1.8.7-p174
  2. rubygems-1.3.5
  3. rubygems-1.3.5

Jadi sejauh pengalaman saya, beberapa package yang harus diinstall terlebih dahulu ( di Kubuntu ya, kalau distro lain ga ikutan ) adalah:

  1. Zlib
  2. Openssl
  3. Mysql dev ( jika ingin menggunakan mysql )

Kalau mau install zlib di kubuntu tinggal ketik aja

sudo apt-get install zlib1g-dev

sementara untuk openssl ketik

sudo apt-get install libopenssl-ruby1.9
sudo apt-get install libssl-dev

untuk library openssl bisa disesuaikan dengan versi rubynya ( dan kalau mau gampang search aja di Software Management kubuntunya ). Setelah itu kita akan menginstall mysql-server ( karena gwa pakainya mysql ). Kalau misalnya anda tidak ingin menggunakan mysql juga tidak apa-apa, karena defaultnya ruby itu menggunakan sqllite.

untuk mysql saya menggunakan command ini

sudo apt-get install mysql-server

sementara untuk library dev mysqlnya gwa menggunakan Software Management( jadi gwa ga gitu ingat packagenya yang mana ). Setelah selesai install mysqlnya kita tinggal download aja source Ruby dari website Ruby on Rails yaitu di www.rubyonrails.org dan pilih menu download. Disana bakal ada tulisan Source: Compile it yourself, nah tinggal klik aja tulisan source nya dan anda sudah dapat sourcenya Ruby.

Langkah-langkahnya kira-kira begini :

  1. Selesai download copy aja file source Rubynya ke mana aja ( ex : /usr/local )
  2. Extract file source tadi ( tar xzvf rubygems-1.3.5.tgz ).
  3. kemudian masuk ke dalam folder yang sudah diextract tadi.
  4. Jalankan langkah untuk compile ( ./configure, make, dan terakhir adalah make install ).
  5. gwa sempat mencoba menggunakan ./configure && make && make install tapi hasilnya tidak berhasil ( jadi kalau ada yang mau coba silakan saja, gwa sih pakai cara manual, jalanin satu2 ).

Nah setelah itu harusnya Ruby kita sudah terinstall, coba jalankan perintah ini :

ruby -v atau ruby --version

Jgn pernah jalanin ruby -version karena akan muncul error message ( harus — ). Kalau sudah terinstall harusnya muncul tulisan seperti ini :

ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]

Nah kalau sudah benar lanjut ke step selanjutnya, kalau gagal coba debugging sendiri aja ya ( googling gitu ). Selanjutnya kita akan menginstall RubyGems atau bisa disebut sebagai Package Managernya Ruby ( mirip apt-get tapi punyanya Ruby ). Langkah-langkahnya :

  1. Masuk lagi ke website Ruby on Rails bagian download, http://rubyonrails.org/download
  2. Cari bagian RubyGems dan pilih Download
  3. Untuk versi terserah pilih yang mana suka la, gwa mah ambil yang paling baru.
  4. Setelah download tinggal pindahin aja ke folder mana aja ( ex : /usr/local ).
  5. Extract lagi RubyGems nya ( tar xzvf rubygems-1.3.5.tgz )
  6. Masuk ke folder yang baru diextract tadi dan jalankan perintah ruby setup.rb
  7. Tunggu proses dan jika tidak terjadi error maka jalankan perintah gem help

Jika gem terinstall dengan benar maka harusnya muncul help tentang penggunaan gem. Sekarang kita akan menginstall rails, tetapi sebelum kita harus menginstall Rake.

gem install rake

Setelah selesai kita tinggal menginstall Rails dengan :

gem install rails

Selesai menginstall rails seharusnya semua langkah sudah selesai, kita tinggal mengetes apakah Ruby on Rails berjalan dengan baik. Masuk ke folder tempat dimana anda akan menyimpan file website anda nanti ( ex: /home/rudy/ruby ). Kemudian ketik perintah ini :

rails blog -d mysql

Dari perintah diatas kita akan membuat folder dengan nama blog dan menggunakan koneksi mysql ( kalau ga pakai -d mysql, secara otomatis ruby akan membuat konfigurasi menggunakan sqllite ).

Masuk ke dalam folder blog tersebut, dan masuk ke dalam folder config dan cari file database.yml, kira-kira isinya begini :

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql
# On Mac OS X:
#   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
# On Mac OS X Leopard:
#   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
#       This sets the ARCHFLAGS environment variable to your native architecture
# On Windows:
#   gem install mysql
#       Choose the win32 build.
#       Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: blog_development
  pool: 5
  username: root
  password:
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: blog_test
  pool: 5
  username: root
  password:
  host: localhost

production:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: blog_production
  pool: 5
  username: root
  password: 
  host: localhost

ubah username dan password sesuai dengan settingan mysql anda. Kemudian keluar dari folder config dan jalankan perintah ini :

rake db:create 

Jika benar maka database akan otomatis terbuat ( jika ada error message berarti ada package mysql yang belum terinstall dengan benar ). Lalu jalankan perintah ini lagi :

script/generate controller home index 

tunggu sampai proses generate selesai ( jika ada yang error, yah anda tau sendiri lah, berarti ada package yang kurang ). Trus jalanin lagi perintah untuk jalanin webservernya :

script/server 

Jika benar maka akan ada proses menjalankan web servernya ( jgn diclose terminalnya karena akan membuat web server tersebut mati ). Untuk mengakses aplikasi Ruby on Rails yang baru dibuat, masuk ke web browser anda dan ketik


http://localhost:3000/

Selamat, anda telah berhasil menginstall Ruby on Rails dan sekarang tinggal belajar configurasinya aja :D