Ruby app only works when Passenger is "disabled" - ruby

I have deployed a Sinatra application on an Ubuntu server using Apache and Passenger. Through some trial and error, I realize the app only works when the passenger module is disabled.
$ a2dismod passenger
After an Apache restart, the app runs as expected.
If I re-enable the module...
$ a2enmod passenger
...I see this warning upon Apache restart:
[warn] module passenger_module is already loaded, skipping
and the app stops working. Apache responds, serving the contents of the vhost's document root, but is not recognized by Passenger.
I'm glad my app works, but I'm not sure how to explain the reversed effect of enabling/disabling the passenger module.

I ran into the same problem: 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 include every *.conf and *.load file from /mods-available to /mods-enabled and than load them.
So if you run in the concerning warning message it means you are loading passenger module twice!
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.
More about this issue here: http://www.duccioarmenise.net/ruby-on-rails/warn-module-passenger_module-is-already-loaded/

This most likely means you've specified 'LoadModule passenger_module ...' twice. The first entry is somewhere not in passenger.conf, the second entry is in passenger.conf.

Related

Phusion passenger is overriding my database config

I am using nginx with Phusion Passenger to bootload a ruby on rails application, if I run the application like
rails s -e production
It does connect correctly to the database, but when bootloaded from nginx with passenger it tries to use root to the database, like ignoring the config files.
I already tried giving permissions, but doesnt look like there is the problem, I already opened the 3 possible host names for root, which could be "localhost", "%" and "127.0.0.1", but in any case it should be openning a connection with root
I would say something is weird on how passenger behaves or that somewhere (not in the app) is ignoring the database.yml or overriding the credentials
in my opinion, I think you should try Passenger Standalone that is what I use and it works fine.

Ruby Grape + Passenger + Apache

I am trying to setup by API server with
grape
passenger
apache2
I installed the gem "passenger" and ran
passenger-install-apache2-module
Placed the following in my "virtual host" configuration
ServerName api.website.com
LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-5.0.6
PassengerDefaultRuby /usr/bin/ruby1.9.1
DocumentRoot /var/www/html/lib/api
But when I restarted the server and tried accessing it via the browser, I just see the folder listing.
What do I need to do different ?
I figured it out. I looked at how Sinatra was being deployed. I had to point the DocumentRoot to a folder "public" (or anything else). Although this folder had to exist in the same directory where my config.ru exists. And then all just worked.
My folder structure looks like this
/app
|- apis.rb
|- config.ru
\- public
virtualhost.conf
DocumentRoot ...../app/public
My solution seems to work. Although would love some explanation to it though :) Anyone has any insight into this ?
Thanks !
You have to point Passenger to a public dir because this allows it to first serve static files from that directory, and if no files were found request the app to process the request. This gives clear semantics for serving static files and performance gains.
request to /img.gif
public/img.gif exists => send it to user
----
request to /users.json
public/users.json doesnt exist =>
send request to app in public/..
So you have to point it to public dir even if you don't have anything in it

Why does mod_jk on Ubuntu 14.04 not connect to tomcat

I am running tomcat 7, Ubuntu 14.04, apache 2.4, Java 8. I am trying to hook up apache with mod_jk to use the tomcat application with only the static resources coming from apache.
Apache is running on port 80 and I can see the file structure and all my static resources. But when I go to the naked url, I only see the apache folder structure. In my understanding mod_jk should be forwarding to the ajp port of tomcat instead.
I installed apache2 and mod_jk (libapache2-mod-jk) by using apt-get. It basically did all the configuration for me (at least it looks like it did). I followed some tutorials to install it, but basically just checked and made sure the steps were taken. The main apache conf file is called apache2.conf and it includes all the .conf files from the folder called mods-enabled. Inside mods-enabled, there is a file called jk.conf. This is the mod-jk conf file and it includes a workers.properties file that is held in my /etc/libapache2-mod-jk folder. (I edited the workers.properties file to point to my tomcat home location and my java home)
The one thing that seemed different from most of the tutorials I read was that my mod jk conf file (jk.conf) had no reference to a file called module/mod_jk.so. I don't know what this file is, and why the folder doesn't have a slash in front of it, but that was what it looked like in all the tutorials.
What would really help is if someone has used the apt-get installation of mod_jk on Ubuntu 14.04 (all of the examples I found were for 12.04).
Is the reason it's not connecting because I don't have the .so file?
Am I mistaken about how ajp is suppossed to work, do I need to do any extra tomcat configuration other than have an ajp connector that looks like this <Connector port="8009" protocol="AJP/1.3" redirectPort="8080" />?
I had not added JkMount to apache2.conf. That solved this.

ELF Header Error and Building Modules In Apache for Jelastic

So I'm building a web app and I decided to move it from my localhost to Jelastic. The app requires one custom module: mod_auth_cas. I followed the instructions on the Jelastic website for adding a module.
The only step I didn't follow was compiling the module against 2.2.15. I tried configuring that version, but I couldn't figure out how to run it concurrently with the 2.2.24 version my Mac runs natively. I figured that a module that worked with 2.2.24 should work with 2.2.15.
I uploaded the .so file to the Jelastic server and added the following LoadModule command to the httpd.conf file:
LoadModule auth_cas_module /usr/lib64/php/modules/mod_auth_cas.so
and restarted Apache. I got the following error:
Failed to start
Stopping httpd [ OK ] Starting httpd
Jelastic autoconfiguration mark httpd
Syntax error on line 161 of /etc/httpd/conf/httpd.conf
Cannot load /usr/lib64/php/modules/mod_auth_cas.so into server
/usr/lib64/php/modules/mod_auth_cas.so invalid ELF header [FAILED]
From the research I did, it seemed as though this error comes when "the installation is
'corrupted' or someone installed something for the wrong processor/binary type."
So I'm trying to figure out what to do. I either need to figure out how to install Apache 2.2.15 and compile a module against that, or I need to figure out what I'm doing wrong on the Jelastic side, or I need to figure out why the .so file is getting corrupted. Which one is it, and how do I do it?
Indeed the problem is the different platforms.
The module was compiled for the correct platform and installed for you.
FYI: To use this module we created a cas.conf file in conf.d please open this file and modify accordingly.
I recommend that you contact your hosting provider and ask them to compile that module for you. The problem is most likely caused by that (compilation on a different system / system that is too dissimilar), or else it's at least the first thing to rule out.

Has anyone setup tomcat to run virtual hosts using mod_jk

I work in OSX primarily with mostly PHP. Normally I work locally using MAMP and virtual hosts setup in my httpd.conf so that I can point a browser to http://some-project and have as many projects as I need setup.
We have a project coming up where we need to serve JSP pages and I would like to set up my local apache server to serve only JSP files to Tomcat and everything else to MAMP using the same virtual hosts setup in:
~/applications/MAMP/conf/apache/httpd.conf
So far I have:
Successfully installed Tomcat
Placed mod_jd.so in
~/applications/MAMP/Library/modules/mod_jk.so
Added the module by placing:
LoadModule jk_module modules/mod_jk.so
in
~/applications/MAMP/conf/apache/httpd.conf
Created /Library/Tomcat/Home/conf/jk/workers.properties
and added the following lines:
workers.tomcat_home=/Library/Tomcat
workers.java_home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
ps=/
worker.list=ajp12, ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp12.type=ajp13
worker.ajp13.mount=/*.jsp
added the following lines:
JkWorkersFile /Library/Tomcat/Home/conf/workers.properties
JkLogFile /Library/Tomcat/Home/logs/mod_jk.log JkLogLevel debug
to
~/applications/MAMP/conf/apache/httpd.conf
I cannot start my MAMP however when these last two lines are present in my httpd.conf.
Does anyone work like this?
Any tips?
Any clear ideas of what I'm doing wrong?
I've found with MAMP that it won't start unless the log files already exist. I create the path to the log file and put in an empty text document named the same as the expected log file and it starts right up.

Resources