Centos+Apache+Phusion+REE=FAIL

apache-2.2centos5phusion-passengerrubyselinux

I have been trying to get Phusion Passenger running on 5.6 for the last couple of days with no luck. Initially, I started with Ruby 1.9.2 under RVM since the default Ruby on RHEL-based distros is quite old. I got everything installed OK but ran into some issues. Thinking it was RVM, I completely removed it along with the default Ruby and installed Ruby Enterprise Ed. 1.8.7.2011-03 into /usr. I am still having the same issues.

When I try to Passenger with the default setup instructions provided by the installer, I got an error message saying cannot find phusion_passenger/analytics_logger. I found very little info about this from Google but from what I can surmise it is a permissions error.
Initially, I tried setting an ACL allowing user access for the apache user to the passenger root directory. Failing that, I tried chmod-ing the passenger root to 777. Next I tried changing the context of the passenger root and its parent directory to httpd_sys_content_t as per section 6.3.5 of the user guide. Last, I tried setting SELinux to permissive. Nothing worked.

After reading through the user guide, I tried the following settings which resulted in a 500 ISE:

PassengerUserSwitching off
PassengerUser apache
PassengerGroup apache

Here is my passenger.conf file minus the above (from /etc/httpd/conf.d):

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/bin/ruby
....
PassengerLogLevel 3

This is the log output from the 500 error:

[ pid=17939 thr=1094539584 file=ext/common/ApplicationPool/Pool.h:939 time=2011-04-30 13:12:17.351 ]: Spawning a process for /var/www/html because there are none for this app group
[ pid=17939 thr=1094539584 file=ext/common/ApplicationPool/../SpawnManager.h:291 time=2011-04-30 13:12:17.352 ]: Spawning a new application process for /var/www/html...
[ pid=17939 thr=1094539584 file=ext/common/ApplicationPool/../SpawnManager.h:427 time=2011-04-30 13:12:17.352 ]: Spawn server died. Attempting to restart it...
[ pid=17939 thr=1094539584 file=ext/common/ApplicationPool/../SpawnManager.h:430 time=2011-04-30 13:12:17.357 ]: Restart seems to be successful.
[ pid=17939 thr=1094539584 file=ext/common/ApplicationPool/../SpawnManager.h:291 time=2011-04-30 13:12:17.359 ]: Spawning a new application process for /var/www/html...
/usr/bin/ruby: error while loading shared libraries: libtcmalloc_minimal.so.0: cannot open shared object file: No such file or directory
[ pid=17939 thr=1094539584 file=ext/common/ApplicationPool/Server.h:297 time=2011-04-30 13:12:17.365 ]: Client 9: SpawnException occured (no error page)
[ pid=17951 thr=47853881642864 file=ext/apache2/Hooks.cpp:865 time=2011-04-30 13:12:17.366 ]: Unexpected error in mod_passenger: Cannot spawn application '/var/www/html': Could not read from the spawn server: Connection reset by peer (104)
  Backtrace:
     in 'virtual Passenger::SessionPtr Passenger::ApplicationPool::Client::get(const Passenger::PoolOptions&)' (Client.h:750)
     in 'Passenger::SessionPtr Hooks::getSession(const Passenger::PoolOptions&)' (Hooks.cpp:297)
     in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:566)

Best Answer

First, when you say you removed the default Ruby, I hope you aren't meaning the one that ships with CentOS. In my experience, it's best to just leave that one alone, and let yum manage it. I install my Ruby/REE versions into /opt/ruby, but they could go in /usr/local, or wherever you wanted.

As far as configuring SELinux, I personally disable it, but permissive shouldn't be any different than that. From a base install, I just add the typical packages needed for compiling packages, and do a full upgrade:

# yum -y install gcc make gcc-c++ cpp automake patch zlib-devel && yum -y upgrade

Then I install REE 1.8.7-2011.03:

# ./installer --dont-install-useful-gems --no-dev-docs --auto /opt/ruby/enterprise-1.8.7-2011.03

Make sure Apache (httpd) is installed, and then install the passenger gem, and the corresponding Apache module:

# /opt/ruby/enterprise-1.8.7-2011.03/bin/gem install --no-rdoc --no-ri --version '= 3.0.7' passenger
# /opt/ruby/enterprise-1.8.7-2011.03/bin/passenger-install-apache2-module -a

Add what it tells you, to Apache's httpd.conf. I use the following:

SetEnv MY_RUBY_HOME "/opt/ruby/enterprise-1.8.7-2011.03"
SetEnv GEM_HOME "/opt/ruby/enterprise-1.8.7-2011.03/lib/ruby/gems/1.8"
SetEnv GEM_PATH "/opt/ruby/enterprise-1.8.7-2011.03/lib/ruby/gems/1.8"
LoadModule passenger_module /opt/ruby/enterprise-1.8.7-2011.03/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby/enterprise-1.8.7-2011.03/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /opt/ruby/enterprise-1.8.7-2011.03/bin/ruby

Then, I deploy a simple Rails application to /home/httpd/app, and add a VirtualHost similar to the following:

<VirtualHost *:80>
  ServerName example.domain.com
  DocumentRoot /home/httpd/app/public
  RackBaseURI /
  RailsEnv production
  PassengerSpawnMethod smart
</VirtualHost>

Make sure all the gems that your application will require are installed, including "rails".

Throughout the setup, you shouldn't have to anything too special with file permissions, other than you will have to keep in mind that your app will run as the user/group of the owner of the Rails app root. This user will have to have at least r-x permissions on all of the /opt/ruby stuff.

I honestly don't know why you are getting the /usr/bin/ruby: error while loading shared libraries: libtcmalloc_minimal.so.0: cannot open shared object file: No such file or directory error, but if you follow the above directions, and make sure not to bother with your system Ruby, you shouldn't have any problems.

I'm sorry that I didn't really answer your question, but I'm hoping my tried and trusted process will work equally as well for you as it does for myself!