Contributor: Md. Tauhidul Islam, Software Engineer, Nascenia

Here are the steps of installing Rails server using VirtualBox.

Get access in VirtualBox server from Local terminal using SSH

The best way to login to a guest Linux VirtualBox VM is port forwarding.

1. Go to Machine > Settings > Network tab

2. Check Cable Connected (if have unchecked)

3. Press ‘Port Forwarding’ button

4. Add a new port forwarding rule as given below –

Name: ssh Protocol: TCP Host IP: 127.0.0.1 Host Port: 3022 Guest IP: Guest Port: 22

5. Press OK button of Port Forwarding Rules window

6. Press OK button of Settings window

7. Select Ubuntu server machine and press Start button

8. Open your terminal and login into server (follow this command as below) –

$ ssh -p 3022 user@127.0.0.1

Where ‘user’ is your username within the VM.

Please be sure, you do not forget to install an ssh server. If ssh command is not working, install it by following this command:

$ sudo apt-get install openssh-server

9. Enter server password

Setting up a Linux server for Rails project

Create new user with sudo access for deploy your project in server –

$ ssh -p 3022 user@127.0.0.1 $ sudo adduser deployer $ sudo adduser deployer sudo

Exit from server and login from new user (deployer) –

$ exit $ ssh -p 3022 deployer@127.0.0.1

Install git in your server –

$ sudo apt-get update $ sudo apt-get install build-essential git-core curl *y

Check if the git is working fine –

$ git --version #git version 1.7.9.5

Install rvm for controlling ruby versions –

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 $ [\curl -sSL https://get.rvm.io | bash -s stable --quiet-curl --ruby=1.9.3] $ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc $ source ~/.profile

Logout ssh and login again –

$ exit $ ssh deployer@127.0.0.1

Check if rvm installation is successful –

$ type rvm | head -n1 #rvm is a function

Install rvm requirements (Generally requirements are installed with rvm but we run this following command for confirmation) –

$ rvm requirements

Check rvm version –

$ rvm -v #rvm 1.21.10 (stable) by Wayne......

Install ruby (select version as needed for your project) –

$ rvm install 1.9.3-p429

Check ruby version –

$ rvm list 1.9.3-p429 $ ruby -v #ruby 1.9.3p429 (2013-05-15 revision 40747) [i686-linux]

Install rails (select version as needed for your project) –

$ gem install rails -v 3.2.13 --no-document

Check rails version –

$ rails -v #Rails 3.2.13

Install mysql database (If your project is developed by using mysql database) –

$ sudo apt-get install mysql-server $ sudo apt-get install mysql-client-core-5.5 $ sudo apt-get install libmysql-ruby libmysqlclient-dev *y $ gem install mysql2

If you face any error as bellow –

[E: Unable to locate package libmysql-ruby]

Then run this following command –

$ sudo apt-get install libmysqlclient-dev libmysqlclient18 ruby-dev *y $ gem install mysql2

Generate ssh key –

$ cd ~ $ ssh-keygen -t rsa -C "your email address"

#==========================start-nginx-installation==================== $ cd ~ $ gem install passenger -v 4.0.1 $ sudo apt-get install libcurl4-openssl-dev *y $ rvmsudo passenger-install-nginx-module *[Enter] *1 *[Enter] #Where do you want to install Nginx to? *[Enter] #This installer has already modified the configuration file for you! ==============

That /etc/hosts has an entry for localhost. It should have something like –

127.0.0.1 localhost.localdomain localhost 127.0.1.1 my-machine

nginx start/stop/restart/reload –

$ echo 'PATH=$PATH:/opt/nginx/sbin' >> ~/.bashrc $ source ~/.profile

Now we can control nginx using –

sudo service nginx stop sudo service nginx start sudo service nginx restart sudo service nginx reload

Run the command to install imagemagick –

$ sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev

Hope this will help you to install Rails server using VirtualBox on your local PC.