[warn] module passenger_module is already loaded

4th dic 2011Ruby on Rails, , , , , , ,

Following the basic instruction to install Phusion Passenger and Apache2 for a Ruby on Rails server I ran into this error: “[warn] module passenger_module is already loaded” on restarting my Apache server…

…at last I addressed the problem and fixed it.

The problem

Given that my software versions are :

- Apache/2.2.14 (Ubuntu)
Phusion Passenger version 3.0.11

And I am working on a Linode with Ruby v. 1.9.2 and RVM.

If you follow passenger installing instruction with this version of Apache you may actually tell Apache to load passenger twice.

Before adding the 3 famous lines to your Apache configuration file:

LoadModule passenger_module /usr/…/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p290/ruby

Check the configuration file apache2.conf for lines like these:

# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

If these lines do exists it means that on start your Apache server will copy every every *.conf and *.load file from /mods-available to /mods-enabled and than include them.

So if you run in the concerning warning message it means you are loading passenger module twice!

The solution

You can take advantage of this Apache feature going to /mods-available, looking for passenger.conf and passenger.load files and edit them instead of apache2.conf.

The ‘LoadModule passenger_module’ line goes into passenger.load, while the other 2 ‘PassengerRoot’ and ‘PassengerRuby’ lines go into passenger.conf.

Then restart your server and you’ll be fine.

Please note that the same mechanism is applied to /sites-available and /sites-enabled, this means that you can take advantage of this mechanism as well including your passenger Virtual Host declarations like:

<VirtualHost *:80>
ServerName depot.yourhost.com
DocumentRoot /home/rubys/work/depot/public/
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>

In /sites-available instead of including them directly in your apache2.conf file!

I think this approach is cleaner and even more maintainable than the one suggested by the passenger installer.

If you found this post useful you may follow me.