(ve):Nginx on thin rails
- This page was last modified on February 22, 2011, at 12:54.
From (mt) Community Wiki
Contents |
This article will cover setting up Ruby on Rails, running with the "thin" server and proxied by Nginx
At the moment, it's more commands than discussion, but that can be edited later.
Install Ruby from Repos
Unfortunately, CentOS doesn't include recent ruby packages. For some applications, an older version of Ruby will work, in which case install from repos (this). Otherwise, you'll need to skip to the next section, Install Ruby from Source.
Installing ruby from the repo is as straight forward as running yum:
$ yum install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc
Verify the ruby version
$ ruby -v ruby 1.8.5 (2006-08-25) [x86_64-linux]
Install Ruby from Source
If you need a more recent version of Ruby, you'll need to install from source.
$ yum groupinstall 'Development Tools' $ yum install readline-devel $ cd ~ $ mkdir ./src $ cd ./src $ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz $ tar xzvf ruby-1.9.1-p376.tar.gz $ cd ruby-1.9.1-p376 $ ./configure && make $ make install
Link to ruby install into /usr/bin
$ ln -s /usr/local/bin/ruby /usr/bin/ruby
And test out the version
$ ruby -v ruby 1.9.1p376 (2009-12-07 revision 26041) [x86_64-linux]
Install Rubygems
Unfortunately, CentOS doesn't currently have recent rubygems in the repos, so we'll need to install it from source.
Start by creating a source folder:
$ cd ~ $ mkdir ./src $ cd ./src
Download the most recent version of rubygems. Make sure to replace 1.3.6 with the current version from the rubygems page.
$ wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
Extract the source, and visit the new rubygems source directory:
$ tar xzvf rubygems-1.3.6.tgz $ cd rubygems-1.3.6
- Tip you can type cd ruby<TAB>, and the shell will complete the folder name for you.
$ ruby setup.rb
Once rubygems is installed, you can update by running
$ gem update
although it's just been installed, so nothing should be out of date yet.
- Tip: If running the `update` command produces an error, try running `yum groupinstall 'Developemnt Libraries'` and then going back into the ruby folder, running `make clean` and then restarting the install from the `./configure` step (including re-running `ruby setup.rb`).
Install Rails
Rails is easy -- really easy
$ gem install rails
Check the install with
$ gem list *** LOCAL GEMS *** actionmailer (2.3.5) actionpack (2.3.5) activerecord (2.3.5) activeresource (2.3.5) activesupport (2.3.5) rack (1.0.1) rails (2.3.5) rake (0.8.7)
Install SQLite
Rails likes some SQLite. So, first make sure that it's installed on the system
$ yum install sqlite sqlite-devel
Then install the SQLite rubygem
$ gem install sqlite3-ruby
Finally, test it out to make sure that ruby sees SQLite
$ irb
irb(main):001:0> require 'sqlite3'
=> true
Installing MySQL
Get MySQL installed (TODO: Article on MySQL?)
$ gem install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config
And that's it
Install OpenSSL
In order to use Ruby on the web, we will need OpenSSL support. Start by installing OpenSSL
$ yum install openssl openssl-devel
Then, build open ssl support into ruby
$ cd ~ $ cd ./src/ruby-1.9.1-p376/ext/openssl $ ruby extconf.rb $ make $ make install
Finally, check to make sure that ruby has OpenSSL support
$ irb
irb(main):001:0> require 'openssl'
=> true
Install thin
After all that setup, installing thin is actually pretty easy
$ gem install thin
To check that thin is properly installed, check the version
$ thin -v thin 1.2.7 codename No Hup
__Note:__ If thin fails with a message about ssl, see the previous section, Installing OpenSSL.