passenger and rmagick on shared hosting

I had been getting so much pain with setting up both passenger and rmagick to up and running in the last week. I’m developing a rails web application that has image processing feature using imagemagick. The problem that i’ve expect is on the deployment stage, and then this problem come true to me. I use shared hosting that offers cpanel with Ruby on Rails compatibility and using CentOS 5.2 as its operating system, but actually the administrator of that hosting don’t know much about it, hmm.. this  is the second problem. It using mongrel and with custom lobbies to the administrator he already gave me the imagemagick feature and rmagick as well for free.

As i’ve said before, that this hosting using mongrel, for this case i search tutorials on how to deploy it. Then i’ve got an helpfull tutorials about deploying rails with mongrel in here:

In simple words, we just simply create rails aplication using cpanel menu with production evirontment, then we need to start our rails application and create rewrite with .htaccess file on ~/public_html directory.

Because of my hosting getting trouble with its mod_rewrite functionality, i can’t get rewriting step works well. Then i ask my hosting to install passenger for simple setup, and.. granted!!! passenger is available..
The simple step of configuring passenger as simply as create symbolic link for ~/public_html to RAILS_ROOT/public. But, what’s happen? i had been getting exception loaderror like this: cannot open shared object file: No such file or directory – /usr/lib/ruby/gems/1.8/gems/rmagick-2.8.0/lib/

What a weird error!! because when i tested it using mongrel, the error doesn’t occurred. It must be error from passenger or rmagick. They’re the suspects..
Then i started to search throug blogs and forums that discussed about passenger and rmagick. If you’ve got a problem like me, i advised you to follow this step by step and test it..

The first way that i had found is adding LDFLAGS to system environtment variables and add it to startup files as well.

export LDFLAGS=”-L/usr/local/lib -Wl,-rpath,/usr/local/lib”

And the result is my rails application still getting its error, and this step is not help. The second way that i’ve found and tried is adding LD_LIBRARY_PATH environtment variable to the system and startup files, and this step is also not works for me.

export LD_LIBRARY_PATH=/usr/local/lib

The first and second way are referenced from here:
In many forums and blogs they’re talking that my error is caused by failed in loading library imagemagick that pointed from some environtment variables like LDFLAGS and LD_LIBRARY_PATH. I’ve already add these environment variables, and why my rails applications still doesn”t work?

I continued searching through forums and blogs again. And big surprise.. i’ve found a blog post from passenger developer. The article talking about my problem, exactly my problem..
I followed the first step, adding environtment variable load in config/environment.rb like this:

ENV['LD_LIBRARY_PATH'] = “#{ENV['LD_LIBRARY_PATH']}:/usr/local/lib”

And then i still can’t get my rails application up and running. Fyi. i’ve already add this syntax on the first line and end line of environment.rb file. What i expected is apache still can’t load this environment variable path. And then i followed the second option of adding environment variable by creating wrapper script, the steps that i’ve done are like these following steps:

  • Create file /usr/local/rmagick_wrapper_script that filled with these syntax:

export LD_LIBRARY_PATH=/usr/local/lib
export LDFLAGS=”-L/usr/local/lib -Wl,-rpath,/usr/local/lib”
exec “/usr/bin/ruby” “$@”

  • Don’t forget to make this file executable by adding chmod +x

  • Add this syntax to apache configuration file

PassengerRuby /usr/local/rmagick_wrapper_script

  • Restart apache

Something that have to be noticed is these step must be runned by administrator or root.
What the result? these steps doesn’t affect to my rails application i still getting exception loaderror. Fyi. the article can be found here:

Hmm.. what the hell with this error..??
Finally i had given up this error to administrator of my hosting. And then two days later the administrator told me that my rails application works now..!!! When i ask him what he has done to my rails application?

He answered that he just added this syntax:

ldconfig /usr/local/lib

And now.. i’m getting happy with my rails application works well.

Tags: ,

blog comments powered by Disqus