Hazelong.com

Malaysian Beauty Blog, Art, Geekery & more...

Tag ∝ mysql

Deploying Rails to Centos 5 : Ruby, Gems & Rails

Hi there, if you have been following this series you would roughly know that I am trying to setup a remote Centos server to house my rails apps. After installing Apache, mySQL and Git, we are now ready to install Ruby, RubyGems & Rails.

Deploying Rails to Centos 5

As I like to have multiple versions of Ruby in my system, I am going to install RVM to handle them. But before all that, we should check if ruby already exists. SSH into your remote server and run

 ruby -v

If terminal shoots you back with a Ruby version number you already have Ruby installed and you should move on to installing rails.

Let’s install RVM by running this:

$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

When you are done installing, you should edit your .bash_profile To do just that,

 vim ~/.bash_profile

Hit I to edit the file and paste in the following:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

Now, hit ESC to exit editing mode and SHIFT+Z twice to get out of vim. After this, you should log out of ssh and then log back in again to refresh the session.

When you are back in again, run this

type rvm | head -1

and they should reply with this:

 rvm is a function

If it doesn’t it means that the .bash_profile isn’t updated yet.

 rvm notes

Run this to see if you missed any dependencies for installing ruby. The missing dependencies should be listed out for you. Just follow the instructions before proceeding.

Now you can finally install Ruby,

rvm get head
rvm reload
rvm install 1.8.7
rvm install 1.9.2

Create a separate gemset for all your ruby versions by running:

rvm --create 1.8.7
rvm --create use 1.9.2

And make one of them your default by typing

rvm --default use 1.9

You can also check if ruby is installed by running

 ruby -v

They should be using your default version that you just set.

The good thing about installing RVM is that they automatically include RubyGems for you already. To check this fact,

 which gem
/Users/mhartl/.rvm/rubies/ruby-head/bin/gem

Now you can install Rails!

gem install rails --version 3.0.6

Check if it is installed by running

 rails -v

Now you can has rails. Woot.
Next, we will set up a test application for rails to try and make it work with Passenger.

Deploying Rails to Centos 5 : mySQL

Hello, this is part two of the series!

If you have played with Rails before, you would know that the default database is SQLite. That is fine for development, for production having mySQL is better for handling more queries.

Deploying Rails to Centos 5

Make sure you have Apache installed before doing this. There are a few dependencies that you should install as well. Connect via ssh to your remote server and run this command

 yum install httpd-devel\
openssl-devel\
zlib-devel\
gcc\
gcc-c++\
curl-devel\
expat-devel\
gettext-devel\
mysql-server\
mysql-devel

Once you are done, you can boot up mysql by doing this

 service mysqld start

And also make sure that mySQL starts when you boot up your server.

chkconfig mysqld on

Now, let’s make sure that we have a database prepped for a test rails application. To do that, run

/usr/bin/mysql -u root -p

Enter your root password if there is any.

You should be greeted with a friendly :

 mysql> 

If you want to change your root password you can do so by running this,

UPDATE mysql.user SET Password = PASSWORD('password') WHERE User = 'root';
FLUSH PRIVILEGES;

Let’s create a database for our rails test application. icon biggrin : Deploying Rails to Centos 5 : mySQL

CREATE DATABASE demodb;

And add a user for this database.

 INSERT INTO mysql.user (User,Host,Password) VALUES('loginname','localhost',PASSWORD('yourpassword'));
GRANT ALL PRIVILEGES ON demodb.* to loginname@localhost;
FLUSH PRIVILEGES;

Now you have a working database! Yay!

For a list of handy commands to communicate with your mySQL database, head here.

Next : Git