Installing Rails 3 on Centos with Apache

This article details a quick install routine I use to get Ruby 1.9.2, Rails 3, Apache,Passenger and Mysql onto a Centos box for development.You don’t need anything special other than a text editor, I use Nano, about 45 minutes and root access.

Please note this install is not tested on any other platform than Centos 5.5.

Starting from a completely fresh Centos install:

#yum install httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel mysql-server mysql-devel –y

Install Ruby 1.9.2 

 

# cd /usr/local/src
# curl -O http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p180.tar.gz
# tar zxvf ruby-1.9.2-p180.tar.gz
# cd ruby-1.9.2-p180.tar.gz
# ./configure --enable-shared --enable-pthread
# make
# make install
# cd ext/zlib/
# ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib
# cd ../../
# make
# make install


Installing RubyGems

# wget https://rubyforge.org/frs/download.php/74922/rubygems-1.8.4.tgz --no-check-certificate
# tar xzvf rubygems-*.tgz
# cd rubygems-*
# ruby setup.rb
#cd ..

Installing Sqlite

In the past I’ve attempted to install Sqlite via Yum with little success, maybe you’ll have more luck than me, but I find the most pain free way is to download the latest amalgamation file from sqlite.org and install by following the steps below:

#wget http://www.sqlite.org/sqlite-amalgamation-3.7.0.1.tar.gz
#tar xvzf sqlite-amalgamation-3.7.0.1.tar.gz
#cd sqlite-3.7.0.1
#./configure --prefix=/usr/local/src/sqlite-3.7.0.1
#make
#make install
#gem install sqlite3-ruby -- --with-sqlite3-dir=/usr/local/src/sqlite-3.7.0.1

Updating RubyGems & installing MySQL, Rails and Passenger

Check if RubyGems has any updates available to the system and to any Gems that may have already been installed:

# gem update --system
# gem update

Now that we are confident that our RubyGems installation is fully up-to-date we will now proceed with installing the MySQL, Rails, Passenger gems.

# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
# gem install rails passenger

Configuring Passenger for Apache 2

To configure Passenger to work with Apache 2, simply execute the following command and follow the on-screen instructions:

# passenger-install-apache2-module

As mentioned in the final step of the Passenger installation you need to make some changes to your Apache configuration:

#nano /etc/httpd/conf/httpd.conf

Add the following LoadModule, and passenger specific entries to your httpd.conf file in the LoadModule section:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby

Finally, we add an Apache Virtual Host entry with reference to our first Ruby on Rails application to our httpd.conf file:

<virtualhost *:80>
RailsEnv development
ServerName app.com
ServerAlias www.app.com
DocumentRoot /var/www/html/blog/public
<directory /var/www/html/blog/public>
AllowOverride all
Options -MultiViews
</directory>
</virtualhost>

Creating our first Ruby on Rails application

In this tutorial we will create a Ruby on Rails application called blog. We will now create the directory structure as we created for our Virtual Host entry:

# cd /var/www/html/

With our directory structure in place we will execute the rails command to create the skeleton of our new Ruby on Rails application:

# rails new blog

Ensure that the apache has permission to all objects within our application:

# chown -R apache.apache *

Finally, we restart Apache:

# service httpd restart

Ok if everything has worked ok http://<yourserveripaddress> should display the Rails ‘smoke test’ page.
That’s it; hopefully this helped you, all comments welcome.

你可能感兴趣的:(centos,Ruby,Rails)