Tuesday, March 22, 2011

Install Passenger with Ruby 1.9.2

It's assumed you use RVM with Ruby 1.9.2

luan@luan-Latitude-D430:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
luan@luan-Latitude-D430:~$ rvm 1.9.2 --passenger
NOTE: If you are using Passenger 3 you no longer need the passenger_ruby,
use the wrapper script for your ruby instead (see 'rvm wrapper')
luan@luan-Latitude-D430:~$ rvm 1.9.2
luan@luan-Latitude-D430:~$ ruby -v

ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
luan@luan-Latitude-D430:~$ gem install passenger
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions. This could take a while...
Fetching: daemon_controller-0.2.6.gem (100%)
Fetching: spruz-0.2.5.gem (100%)
Fetching: file-tail-1.0.5.gem (100%)
Fetching: passenger-3.0.5.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-0.2.6
Successfully installed spruz-0.2.5
Successfully installed file-tail-1.0.5
Successfully installed passenger-3.0.5
5 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for daemon_controller-0.2.6...
Installing ri documentation for spruz-0.2.5...
Installing ri documentation for file-tail-1.0.5...
Installing ri documentation for passenger-3.0.5...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for daemon_controller-0.2.6...
Installing RDoc documentation for spruz-0.2.5...
Installing RDoc documentation for file-tail-1.0.5...
Installing RDoc documentation for passenger-3.0.5...

luan@luan-Latitude-D430:~$rvmsudo passenger-install-nginx-module


luan@luan-Latitude-D430:~$git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git
luan@luan-Latitude-D430:~$sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx
luan@luan-Latitude-D430:~$sudo chown root:root /etc/init.d/nginx

To do next:

luan@luan-Latitude-D430:~$ cd to-your-rails-app-folder

luan@luan-Latitude-D430:~$bundle install

luan@luan-Latitude-D430:~$rake db:setup RAILS_ENV=production

luan@luan-Latitude-D430:~$sudo /etc/init.d/nginx restart

Saturday, March 12, 2011

Install chromium on Linux Mint 10

1. open terminal

2. sudo add-apt-repository ppa:chromium-daily/stable

3. sudo apt-get update

4. sudo apt-get install chromium-browser

Tuesday, March 1, 2011

Install Git on Ubuntu 10.10

I am working on a project, and I would like to have a repository to keep my code.
After looking around cvs, svn and git, I finally would like to try out git.

You can read more about git. It's a free online book


Sever Install


$sudo apt-get install git-core
$sudo apt-get install gitolite
$sudo apt-get install git-daemon-ru

Add a user to the server.

In order for you to access into the server without enter the password, you need to setup ssh key authentication.
Here is an example on how to generate ssh key. If you already have ssh key authentication, you may skip this step.


Generating public/private rsa key pair.
Enter file in which to save the key (/home/gituser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/gituser/.ssh/id_rsa.
Your public key has been saved in /home/gituser/.ssh/id_rsa.pub.
The key fingerprint is:
61:bf:f5:2d:f6:ed:cd:10:b7:0c:be:5d:4d:8f:a3:0d gituser@client

When you are done, copy this key into the server. From your client, scp into your server as below.


$scp /home/gituser/.ssh/id_rsa.pub user@gitserver:/tmp/gituser.pub

Now you need to go back to the gitserver and add this key to git:


$chmod 666 /tmp/gituser.pub
$su gitolite
$gl-setup /tmp/gituser.pub

You have added a user to the git server.

Client configuration

You may config your git in the configuration. I encourage you to read chapter 1 and chapter 2 from http://progit.org/


$git config --global user.name "firstname lastname"
$git config --global user.email email@email.com

Adding a repository to your new git server

Now we may setup a test repository.
For us to do this, we need first check out the gitolite-admin repository from the git server
and edit the configuration file and then check it back in.


$git clone gitolite@server:gitolite-admin
$cd gitolite-admin/
$vi conf/gitolite.conf

This file should already contain a couple of repositories:


repo gitolite-admin
RW+ = gituser

repo testing
RW+ = @all

You may add a new project into the file. I copy the "testing" and paste to new line and modify as below:


repo mytest
RW+ = gituser

Save that file, and we can then commit it back to the server:


$git commit -m "Added mytest repo" conf/gitolite.conf
$git push

You should see output like the following, this creates the repository on the git server:


Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 398 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Already on 'master'
creating mytest...
Initialized empty Git repository in /var/lib/gitolite/repositories/mytest.git/
To gitolite@gitserver:gitolite-admin
610d463..98a9226 master -> master

Now that we have a new repository, we can clone it to our local client system and add files to it:


$git clone gitolite@gitserver:mytest
$cd mytest
$echo “This is a test” > readme.txt
$git add .
$git commit -m "Initial checkin of readme.txt"
$git push origin master

To test it, you can go ahead a delete entire direcotry, and clone it back.

Here are some good references:

1. http://help.github.com/git-cheat-sheets/
2. http://www-cs-students.stanford.edu/~blynn/gitmagic/

Sunday, February 6, 2011

crontab doesn't work with ruby rvm

I am using RVM ruby, and crontab doesn't work properly.

crontab doesn't look at .bashrc or .bash_profile. Therefore, we have to add this into

sudo vi /etc/profile. Just source whatever in profile.

luan@luan-laptop:/etc$ head profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

# luan added here

source /home/luan/.bash_profile

# end luan added

if [ -d /etc/profile.d ]; then

Thursday, January 27, 2011

SSH without enter password

Step 1 of 2 : On local machine: Generate Authentication Keys

$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/luan/.ssh/id_rsa):
Accept the default choice. Hit enter.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Hit enter twice. A passphrase encrypts your private key so that no one can see it. However, you should NOT encrypt your private key if you want a password-less login.

The key fingerprint is:
5e:26:52:34:a1:22:18:68:11:11:7d:8d:c6:d5:4b:bf luan@luan.com
What just happened?

On your local server you just created 2 files in your ~/.ssh directory.

cd ~/.ssh
ls -l
-rw------- 1 luan luan 1675 2011-01-27 17:27 id_rsa
-rw-r--r-- 1 luan luan 411 2011-01-27 17:27 id_rsa.pub
id_rsa contains your private key. id_rsa.pub contains your public key.

Step 2 of 2 : On remote machine: authorize password less login

Login to remote machine

$ssh hostname -l username
The authenticity of host 'luan.com (XXX.XXX.XXX.XX)' can't be established.
RSA key fingerprint is 44.2b:93:ce:1b:1b:99:3a:6d:91:d1:50:aa:0d:87:40.
Are you sure you want to continue connecting (yes/no)?
Type yes and hit enter.

Warning: Permanently added 'luan.com,XXX.XXX.XXX.XX' (RSA) to the list of known hosts.
username@luan.com's password:
Enter your password, and hit enter.
Create a .ssh directory on the remote machine and create a .authorized_keys file in that directory. You need to copy the entire contents of your local machine’s ‘id_rsa.pub’ and paste it in the .authorized_keys file on the remote server.

$mkdir -p .ssh
$chmod 700 .ssh
$cd .ssh
$touch authorized_keys
$chmod 600 authorized_keys
$vi authorized_keys

# copy-paste the entire contents of your local machine's ~/.ssh/id_rsa.pub file in authorized_keys
# logout
Important: Make sure you have the right permissions for .ssh directory and authorized_keys file, as shown in chmod command above otherwise SSH will not honor your authorized_keys.

You should now be able to login to the remote server without typing your password.

# type this command from your local machine
$ssh hostname -l username
SSH should log you in without password! Now, you can also scp or rsync (over ssh) without having to enter your password.

Install Postgresql 9.0 on Ubuntu 10.10

Install Postgresql 9.0 Ubuntu

sudo apt-get install python-software-propertie
sudo add-apt-repository ppa:pitti/postgresql

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install postgresql-9.0 libpq-dev

sudo -u postgres psql

Once logged in to the SQL interface, set a password for the postgres role:


You need this password to connect to the PostgreSQL server remotely with the postgres role, as described below.

To exit the PostgreSQL shell, type: