Archive for August, 2008

mysql gem and mysql NOT from RPM

Have you ever seen this:

>> require ‘mysql’
LoadError: cannot open shared object file: No such file or directory – /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/
from /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require’
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require’
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in’
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require’
from (irb):2

I found this happens when your environment for mysql is not setup correctly. The fix is easy. All you need is to add a file in the /etc/profile.d directory called with the correct exports and re-login…

[root@heimdull log]# cat /etc/profile.d/
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/mysql/bin:${PATH}

That fixes the binary and library paths… MAKE SURE THERE ARE NO MYSQL RPMS INSTALLED…

rpm -qa | grep mysql should give no mysql-[version] or mysql-server-[version] or mysql-devel-[version]

log-in and out…

install the gem

[root@heimdull ~]# gem install mysql — –with-mysql-config=`which mysql_config`
Building native extensions. This could take a while…
Successfully installed mysql-2.7
1 gem installed

test the new gem:

[root@heimdull current]# RAILS_ENV=production ruby script/console
Loading production environment (Rails 2.1.0)
>> require ‘’
=> []
>> puts Mysql::VERSION
=> nil
>> exit

Using thin with rails (apache frontend)

prerequisites (running on redhat/centos 5)

ruby 1.8.6+ (download, untar, configure, make, make install [reboot])
rubygems (download, untar, ruby rubygems/setup.rb)
rails (gem install rails)
thin (gem install thin)
apache 2.2 (installs apache to /usr/local/apache2 with mod_proxy/_balancer)

  • download
  • untar
  • ./configure –enable-proxy –enable-proxy-balancer –enable-rewrite –enable-deflate –enable-headers
  • make && make install

Install the thin run script
# thin install

Installing the thin configuration file
# vi /etc/thin/thin_conf.yml

user: daemon
group: daemon
chdir: /var/www/rails_app/current
log: log/mongrel.log
pid: tmp/pids/
environment: production
port: 8000
servers: 3

# /etc/init.d/thin start

Now lets add the proxy configs to apache…

in httpd.conf:

Include conf/extra/*.conf

now add your vhost config in conf/extra/httpd-rails_app.conf …

# vi conf/extra/httpd-rails_app.conf

# Always keep the host header
ProxyPreserveHost On


DocumentRoot /var/www/rails_app/current/public

Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

ProxyPass /images !
ProxyPass /javascripts !
ProxyPass /stylesheets !
ProxyPass /uploads !
ProxyPass /photos !

ProxyPass / balancer://rails_cluster/
ProxyPassReverse / balancer://rails_cluster/

# =============================================
# Configure Deflate Module (gzip)
# =============================================

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# =============================================
# Virtualhost logs
# =============================================
# Mark requests for the robots.txt file
SetEnvIf Request_URI “^/robots\.txt$” dontlog

ErrorLog logs/www/error_log
CustomLog logs/www/access_log combined env=!dontlog

# /usr/local/apache2/bin/apachectl start

rails thin apache all working together…. 🙂