21
votes

I'm trying to setup a ruby on rails server on ubuntu10.10 with apache2 and mod_rails (Phusion Passenger).

I already installed ruby 1.9.2-p0 and rails 3.0.8 and installed Passenger with the passenger-install-apache2-module and the passenger gem (v3.0.7).

It then tells me to add 3 lines to my Apache config file. So I added these lines to '/etc/apache2/apache2.conf':

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby

And I edited my '/etc/apache2/httpd.conf' and added:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName 192.168.0.2
DocumentRoot /var/www/webop/public

<Directory /var/www/webop/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

I also found out that the file mod_passenger.so in /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/ actually does not exist, its name is mod_passenger.c. But I don't get any errors from that.

The server should only be accessible through a LAN. When I access the server I see all the files and directories in the public folder of my app but the app itself does not get started.

When I restart apache it tells me that mod_rails is already loaded so I guess that passenger is running but I can't figure out why it doesn't start my app!

Thanks in advance!

4

4 Answers

39
votes

The reason mod_passenger.so does not exist is because you haven't installed the Apache module. Execute:

passenger-install-apache2-module

This will create the mod_passenger.so file inside your gem directory, and give you three lines to copy into your apache2.conf file.

The passenger module is installed in your current gemset so you shouldn't get any conflicts between projects. You can use any compatible version of Ruby, and any gemset you like, via RVM, and possibly also RBENV. This makes for a nice easy upgrade path from one version of Ruby to the next.

12
votes

I finally figured out what the problem was: I messed up my ruby installation.

In /usr/local/ I had ruby1.9.2-p0 installed (which was the version I wanted to use) but in /usr/ i had ruby1.8.7 installed.

Passenger was confused which ruby version to use so I changed the LoadModule, PassengerRoot and PassengerRuby paths within apache2/mods-enabled/passenger.load and .config to the correct paths and it finally worked! Both files were created automatically which also caused the problem of a redefinition: On apache startup there was a warning 'mod_passenger already loaded'. So I removed

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby

from the apache config and the warning disappeared!

Probably this will help someone else some day!

3
votes

I have come across a cleaner solution today. This might help future users. The command -

passenger-install-apache2-module

tells me to put these three lines in apache configuration file.

LoadModule passenger_module /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59
     PassengerDefaultRuby /home/anwar/.rvm/gems/ruby-2.2.0/wrappers/ruby
   </IfModule>

But, where is that configuration file? The answer is the configuration files are seperated into many pieces and they reside in /etc/apache2/mods-available.

So you should do three things -

  1. Create a file ending with .load in /etc/apache2/mods-available folder. I used passenger.load.

  2. Paste the three lines in that file and save the file.

  3. Now in terminal use sudo a2enmod <module-conf-filename> to enable the module. In my case, the file was, passenger.load. So, I used

    sudo a2enmod passenger
    

Now, restart the server and use the command apache2ctl -M to find that passenger module is enabled.

1
votes

I think they want you to put those three lines in your httpd.conf file, not in your apache2.conf. At least that's how I've always done it.