Deploying Rails Apps on CentOS 4

From NHRubyWiki

Jump to: navigation, search

Contents

Introduction

One of the good things about holding out until recently to get into Ruby on Rails development is that a lot of thorny issues have been resolved. Well, most of them, at least. For a long time people have been debating the merits and drawbacks of various Rails deployment environments, including FastCGI vs. Proxying. The consensus now seems to be to avoid FastCGI. And while many people are using alternative web servers for their Rails apps, those of us who have been Apache sysadmins for many years would prefer to stick with our battle-scarred friend. If you're only looking for raw performance in a Rails-only deployment environment, you should seriously consider some of the alternative web servers, but Apache can still deliver rock-solid stability and performance for your Rails apps.

Unfortunately, setting up a Rails deployment envrionment isn't a walk in the park for most enterprise Linux distributions. The main reason for this is that Apache v2.2 is required, and most distros still use Apache v2.0. In order to balance incoming HTTP requests to multiple Rails application servers, which is necessary because Rails is not a thread-safe environment, you need to use Apache's mod_proxy_balancer module. And mod_proxy_balancer requires Apache v2.2 for things to run smoothly.

I'm personally running CentOS 4.4 on my deployment server, which comes with Apache 2.0.52. CentOS is a free clone of RedHat Enterprise Linux, identical in every way except for some trademark-related graphics and text. Which means that these instructions also apply to RHEL 4.4.

I started writing this because, at the time, most of the documentation (primarily on blogs) didn't work for me. Others simply gave instructions on how to remove all web-related RPMs from your system and install Apache from source. I've encountered plenty of problems in the past from mixing source-compiled apps and RPMs, and don't want my web services to stop functioning one day when a shared library gets an upgrade.

Fortunately, Jason Litka's blog posts have been updated recently and he provides some slightly customized SRPMs that will compile cleanly, as well as 32-bit and 64-bit binary RPMs for RHEL/CentOS 4 & 5. These instructions are now mostly a re-hash of what he has written for compilation of the SRPMs.

Install Apache 2.2 RPMs for CentOS 4.4

Since Jason provides binary RPMs for Apache 2.2.4, it's not even necessary to recompile them anymore, so this section is much shorter than it used to be. Still, you'll need a full development environment to recompile PHP and other packages later on, so you should set up a separate development box or virtual machine to complete this guide.

Step 1: Perform an "Everything" install of CentOS 4.4

I started with an "Everything" install of CentOS 4.4 in a VMWare session. You could do this on a spare development machine if you don't have VMWare. Make sure to run up2date first to ensure you've got the latest versions of all packages installed.

Step 2: Remove Apache and its dependencies

Remove the following packages (this constitutes apache and all of its dependencies):

rpm -e apr apr-devel apr-util apr-util-devel httpd httpd-suexec httpd-devel httpd-manual \
       system-config-httpd mod_auth_mysql mod_auth_pgsql mod_authz_ldap mod_auth_kerb mod_ssl \
       php php-pgsql php-imap php-snmp php-xmlrpc php-pear php-odbc php-ncurses php-mysql \
       php-mbstring php-ldap php-gd php-domxml php-devel mod_python mod_perl mod_perl-devel \
       mailman squirrelmail subversion mod_dav_svn subversion-perl subversion-devel webalizer htdig-web

Note, the above is split over several lines but is actually run as one command.

Step 3: Install the Apache 2.2 binary RPMs

Now install the following binary RPMs found at the end of this blog post by Jason Litka:

rpm -Uvh apr apr-devel apr-util apr-util-devel pcre pcre-devel httpd httpd-devel mod_ssl

You can install httpd-manual if you like. I personally prefer to go to apache.org when reading documentation on Apache.

Compile and Install PHP 5.2.3 from SRPMs

Step 1: Recompile the PHP 5.2.3 Source RPM

Assuming this is a typical production environment, you probably also have some PHP apps you need to serve. Fortunately, Jason Litka's blog also includes a customized SRPM for PHP 5.2.3. Download it and install the source RPM with:

rpm -ivh php-5.2.3-jason.2.src.rpm

You'll see some warnings that the user "brewbuilder" doesn't exist. They are safe to ignore.

Now, use rpmbuild to compile and build the PHP binary RPMs:

cd /usr/src/redhat/SPECS/
rpmbuild -bb php.spec

This will take a while (about 20 minutes on my Athlon 3000+ under VMWare). When it finishes, you'll be left with several binary PHP RPMs in /usr/src/redhat/RPMS/i386/. You need to install at least the following ones to continue and be able to recompile the php-pear SRPM:

rpm -Uvh php-5.2.3-jason.2.i386.rpm php-common-5.2.3-jason.2.i386.rpm php-devel-5.2.3-jason.2.i386.rpm php-cli-5.2.3-jason.2.i386.rpm

Step 2: Compile and Install PHP-PEAR from SRPM

Here is one point where Jason's blog is already out of date (and he only wrote it a couple of weeks ago!). The latest version of PHP PEAR for Fedora Core is now 1.5.0-1. Download the SRPM from here.

Once again, install the SRPM, ignoring the "brewbuilder" user warnings.

rpm -ivh php-pear-1.5.0-1.src.rpm

Then compile and build PHP-PEAR with rpmbuild:

cd /usr/src/redhat/SPECS/
rpmbuild -bb php-pear.spec

The PHP PEAR library is not architecture-specific, so its binary RPM will be found in the noarch directory. Go ahead and install it:

cd /usr/src/redhat/RPMS/noarch/
rpm -Uvh php-pear-1.5.0-1.noarch.rpm

There, you're now have working binary RPMs for Apache 2.2.4 and PHP 5.2.3. You can take these RPMs and install them on your production server.

Personal tools