Search

Recent Posts

Tags


« | Main | »

mod_rails AKA mod_rack AKA mod_passenger AKA mod…

By Dale Reagan | January 27, 2012

mod_rails AKA mod_rack AKA mod_passenger AKA mod_works_some_times

Mixing:  Apache 2.x, Ruby on Rails 3.x, Passenger 3.0.9, Fedora Linux (FC 13.)

As always the problems that you encounter may be self-inflicted – in this case I had to ‘turn off’ anything that I thought that I knew about configuring Apache…   The mod_passenger documentation provides many examples  but as I followed those steps I only found errors…  I successfully DUPLICATED following ‘the docs’ to multiple non-working implementations of mod_passenger (Phusion Passenger) using multiple Linux virtual machines – I now dub Passenger mod_passenger_confusion…

I am successfully serving an Empty/New Rails project using a config similar to what is described here.  Of course I would prefer a dynamic environment where I did not need to make any system level/server changes to add a new application – even a test application.

Mod_Rails/Mod_Passenger/Mod_Rack seems to be the answer…

Since I am using RVM (Ruby Version Manager) the module paths are a bit long…

The only way that I could get a simple ‘hello world’ Rack to work was by using the setup below – this would work fine for ONE app but the point is to be able to deploy multiple apps without this manual stuff.

File:  /etc/httpd/conf.d/passenger.conf (Apache 2.x)

I found many, many examples using ‘virtual hosts’ and ALL of them used FQDNs – there is NO REASON to use a ‘real’ FQDN for TESTING – provided that your test system is configured to use the /etc/hosts files for simple DNS resolution, i.e.

127.0.0.1    railsapp3  railsapp3.test
# OR some IP using internal IP address space
192.168.10.143    railsapp3  railsapp3.test

Note that if you are using a proxy like Squid then the above also works on any PC on your local network that uses the proxy since it will use the DNS resolution on the server (at least that is how I configured it…)

Sample Apache (2) config file below:  /etc/httpd/conf.d/passenger.conf

#############
LoadModule passenger_module /usr/local/rvm/gems/some_long_path/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/some_long_path/passenger-3.0.9
PassengerRuby /usr/local/rvm/wrappers/some_long_path/ruby

#############
<VirtualHost *:80>
  ServerName railsapp3.test
 DocumentRoot /var/www/html/rails_apps/hello_world/
 PassengerAppRoot /var/www/html/rails_apps/hello_world/

### Passenger error #2
  RailsBaseURI /hello_world
  RailsBaseURI /app_three
  RailsBaseURI /rack_example2
  RailsBaseURI /rack_example3

  PassengerResolveSymlinksInDocumentRoot  on
  PassengerUser apache
  PassengerGroup apache
  PassengerDefaultUser apache
  PassengerDefaultGroup apache

  <Directory /var/www/html/rails_apps/>
     AllowOverride all
       Options -MultiViews FollowSymLinks
       Allow from all
  </Directory>
</VirtualHost>

The Error Page that I see when I remove ‘hello_world’ from the DocumentRoot and PassengerAppRoot paths:

Ruby on Rails application could not be started

A source file that the application requires, is missing.

Further information about the error may have been written to the application’s log file. Please check it in order to analyse the problem.

Error message:
no such file to load — /var/www/html/rails_apps/config/environment
Exception class:
LoadError
Application root:
/var/www/html/rails_apps/
Backtrace: (~20 lines or Ruby/Rails code…)

After too much time experimenting and getting non-working results, here is A solution/FIX – simplify:

  1. Create one master Apache configuration file for all Generic Passenger settings and
  2. One configuration file for EACH application using Unique Virtual Host Names (for testing)
  3. Create a unique DNS entry OR an entry in /etc/hosts for as many Test-Virtual-Hosts as needed
  4. This approach does REQUIRE a re-start of Apache (and re-start Squid as well) if you add/remove virtual hosts; however, you should be able to simple replace the contents of any existing application folder to cause semi-dynamic ‘updates’…
######  /etc/httpd/conf.d/passenger.conf | Fedora Apache 2 #####
LoadModule passenger_module /usr/local/rvm/PATH_TO//mod_passenger.so
PassengerRoot /usr/local/rvm/PATH_TO/passenger-3.0.9
PassengerRuby /usr/local/rvm/PATH_TO/ruby
##
### debug ###
PassengerDebugLogFile /var/log/httpd/passdebug.log
PassengerLogLevel 3
###
### other passenger defaults
PassengerUser apache
PassengerGroup apache
PassengerDefaultUser apache
PassengerDefaultGroup apache

For each Virtual-Host/App combo a new file is used, i.e.:   /etc/httpd/conf.d/railsapp3.conf

##### railsapp3.conf | Apache 2 ####
<VirtualHost *:80>
        ServerName railsapp3.test
        ServerAlias railsapp3
RailsEnv development
#RackEnv development
        DocumentRoot /var/www/html/rails_apps/APP_FOLDER/public
</VirtualHost>
#############

The above works fine for an internal Test server, but, of course would require DNS updates for testing via external browsers…  A sample list of /path_to_web_files/www/rails_apps with APP_FOLDER folders and unique Test-Domains:

  1. demo_app |   http://railsapp1
  2. first_app |   http://railsapp2
  3. hello_world  |   http://railsapp3
  4. r3tutorial  |    http://railsapp4
  5. sample_app  |    http://railsapp5
  6. sample_app_3_1  |    http://railsapp6

Note that if you do not set the RailsEnv or RackEnv to ‘development’ then the default of ‘production’ is automatically set; this may cause your application to fail (most likely due to lack of needed database files/data…)  Note that several weeks have passed prior to posting this so there may be new changes/fixes/solutions for the issues discussed here.   As always, your mileage should vary a bit. 🙂

Topics: Computer Technology, ROR | Comments Off on mod_rails AKA mod_rack AKA mod_passenger AKA mod…

Comments are closed.


________________________________________________
YOUR GeoIP Data | Ip: 73.21.121.1
Continent: NA | Country Code: US | Country Name: United States
Region: | State/Region Name: | City:
(US only) Area Code: 0 | Postal code/Zip:
Latitude: 38.000000 | Longitude: -97.000000
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________