Passenger just showing directory in Apache - ruby-on-rails-3

I am trying to use Passenger to deploy a rails app on Ubuntu with Apache. I've followed pretty much every guide I could find on configuring Passenger with Apache/Ubuntu. However, when I go to the site, I just see the actual file directories and not the running version of the application. If i switch to the /public directory I just see the public directory when I go to the site. I can start and stop the rails server by calling rails s without getting any errors, but still am not able to see the running version of the application. Does anyone ran into similar problems? Is there a good starting point anyone could suggest I look at? I'm not sure if the problem is with apache or passenger.
Apache config
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRuby /usr/bin/ruby
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName http://www.myapp.com/
DocumentRoot /var/www/myapp/current/
<Directory /var/www/myapp/current/public>
Allow from all
</Directory>
When I restart apache, I get a message stating [Sun Nov 06 14:43:48 2011] [warn] module passenger_module is already loaded, skipping I'm not sure if this is an error or is normal.
Update
When I run find / -name 'mod_passenger.so' I get two locations:
/usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
/usr/lib/apache2/modules/mod_passenger.so
Update 2
I have several passenger.config files
/etc/apache2/mods-enabled/passenger.conf
/etc/apache2/mods-available/passenger.conf
/usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/debian/passenger.conf
Each of the passenger.conf files has the following:
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
</IfModule>

Try to put following in apache config file
<Directory /var/www/myapp/current/public>
Allow from all
#Add following line
Options +Includes -Indexes
</Directory>

You may have mod_passenger.so symlinked into your apache2/mods-enabled directory. This would account for the double import.
Run
a2dismod mod_passenger.so
to remove any symlink, then restart Apache.

Related

Passenger directives not working in Apache 2.4 .htaccess

I am trying to load a NodeJS App from Apache+Passenger.
OS: Centos 7 / CloudLinux release 7.9
Apache: 2.4.6 ( httpd-2.4.6-97.el7_9.cloudlinux.x86_64 )
Passenger: Phusion Passenger 6.0.7 ( passenger-6.0.7-1.el7.x86_64, mod_passenger-6.0.7-1.el7.x86_64 ) from Passenger's Yum repo
The virtual host points to /home/vhost1/public_html and the NodeJS App points to /home/vhost1/nodeapps/np1-pass/np1-pass.js
When I run this config via Passenger entries in Apache's config, the application works and is accessible from http://virtual-host/np1-pass/ .
The entry in Apache's config is as under :
<VirtualHost *:80>
ServerName virtual-host
DocumentRoot /home/vhost1/public_html
<Directory /home/vhost1>
# Relax Apache security settings
AllowOverride all
Require all granted
# MultiViews must be turned off
Options -MultiViews
</Directory>
<Directory /home/vhost1/public_html>
# Relax Apache security settings
AllowOverride all
Require all granted
# MultiViews must be turned off
Options -MultiViews
</Directory>
Alias /np1-pass /home/vhost1/nodeapps/np1-pass/public
<Location /np1-pass>
PassengerAppEnv development
Passengerapproot /home/vhost1/nodeapps/np1-pass
PassengerBaseURI "/np1-pass"
PassengerNodejs "/home/vhost1/bin/node"
PassengerAppType node
PassengerStartupFile np1-pass.js
</Location>
</VirtualHost>
What now I have been trying was to move over Passenger directives to the .htaccess file under /home/vhost1/public_html/np1-pass (of-course after removing those directives and the alias and location entry from the Apache config) so that a virtual host owner is able to fire the application without modifying Apache's config, then I get the error
PassengerAppRoot not allowed here, referer: http://virtual-host/np1-pass/
A similar .htaccess works fine for CloudLinux 7 on a cPanel server with Passenger ea-apache24-mod-alt-passenger-5.3.7-9.el7.cloudlinux.x86_64 package installed
When I was looking into various solutions, I came across two documents
https://www.phusionpassenger.com/docs/references/config_reference/apache/#passengerapproot
https://www.phusionpassenger.com/library/config/apache/reference/#passengerapproot
W.r.t. Passenger directives in the 1st link document, under the directive's context .htaccess is missing . But same is present in the 2nd link document
Now I have 2 questions
Are both documents correct or am I missing something. ?
And why the same setup is working fine on CloudLinux 7 on a cPanel server with Passenger ea-apache24-mod-alt-passenger-5.3.7-9.el7.cloudlinux.x86_64 package installed ?
Thanks
Kirti Singh
W.r.t. the question
Are both documents correct or am I missing something. ?
I can't say about that, but I found this useful link https://blog.phusion.nl/2018/01/29/passenger-5-2-0/ which states that many Passenger .htaccess directives have been disabled since Passenger 5.2.0 . But still as both links mentioned in the original question do exist, those links should have had a version prefixed or there should have been a clarification in their content.
Now w.r.t. the 2nd question
And why the same setup is working fine on CloudLinux 7 on a cPanel server with Passenger ea-apache24-mod-alt-passenger-5.3.7-9.el7.cloudlinux.x86_64 package installed ?
I can't say how CloudLinux is doing it, but I was able to run passenger directives via .htaccess by uninstalling the passenger 6.0.7 and the corresponding mod_passenger , and then by installing the old passenger version 5.1 and its corresponding mod_passenger
`yum remove passenger
yum install passenger-5.1.12-1.el7
yum install mod_passenger-5.1.12-1.el7`
This solved my problem and now I am able to load NodeJS apps via .htaccess
I hope my answer helps others who struggle with this issue.

Invalid command 'PassengerAppRoot', perhaps misspelled or defined by a module not included in the server configuration

I have followed every step for installation given in Installing Passenger + Apache on a Linux/Unix production server
for Node.js apps + Red Hat 6 / CentOS 6 (with RPM) and everything worked but when I am trying to configure my subdomain in virtualhost on my centos 6 server using WHM to host my botkit bot, I get this error :
The “/usr/local/apache/bin/httpd” command (process 27088) reported
error number 1 when it ended. Configuration problem detected on line 9
of file /usr/local/apache/conf/includes/post_virtualhost_2.conf.tmp:
Invalid command 'PassengerAppRoot', perhaps misspelled or defined by a
module not included in the server configuration ---
/usr/local/apache/conf/includes/post_virtualhost_2.conf.tmp --- 3
ServerAlias subdomain.mydomain.com 4 ServerAdmin
adminserver#mydomain.com 5 6 7 # Tell Apache and Passenger where your
app's code directory is 8 DocumentRoot /var/www/MyApp/Code/public 9
===> PassengerAppRoot /var/www/MyApp/Code <=== 10 #Error logging 11 ErrorLog logs/subdomain-error_log 12 CustomLog
logs/subdomain-access_log common 13 14 # Tell Passenger that your app
is a Node.js app 15 PassengerAppType node ---
/usr/local/apache/conf/includes/post_virtualhost_2.conf.tmp ---
Here is my configuration:
<VirtualHost *:80>
ServerName www.subdomain.mydomain.com
ServerAlias subdomain.mydomain.com
ServerAdmin adminserver#mydomain.com
# Tell Apache and Passenger where your app's code directory is
DocumentRoot /var/www/MyApp/code/public
PassengerAppRoot /var/www/MyApp/code
#Error logging
ErrorLog logs/votebot-error_log
CustomLog logs/votebot-access_log common
# Tell Passenger that your app is a Node.js app
PassengerAppType node
PassengerStartupFile bot.js
# Relax Apache security settings
<Directory /var/www/MyApp/code/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
I tried to remove the configuration and pass via .htaccess :
PassengerEnabled on
PassengerAppRoot /var/www/MyApp/code
SetEnv NODE_ENV production
SetEnv NODE_PATH /usr/lib/node_modules
PassengerAppType node
PassengerStartupFile bot.js
But still it is not working.
I checked lately and got the following message when validating passenger :
* Checking whether this Passenger install is in PATH... ✓
* Checking whether there are no other Passenger installations... (!)
You are currently validating against Phusion Passenger 5.1.8, located in:
/usr/bin/passenger
Besides this Passenger installation, the following other
Passenger installations have also been detected:
/usr/local/rvm/gems/ruby-2.4.1/bin/passenger
Please uninstall these other Passenger installations to avoid
confusion or conflicts.
The problem is I don't know what are the steps to uninstall /usr/local/rvm/gems/ruby-2.4.1/bin/passenger .
That error means that the Passenger module hasn't been loaded with a LoadModule passenger_module /path/to/.../passenger/buildout/apache2/mod_passenger.so line in your apache config before the Passenger config options are specified.
If sudo /usr/bin/passenger-config validate-install passed the apache config test, then you have multiple apache configs and the wrong one is being loaded when you get the error.
From your error the conf is at /usr/local/apache/conf/, look for any LoadModule lines in the config with fgrep -RH LoadModule /usr/local/apache/conf/ and add a line to load the Passenger module.

apache + redmine 403 - premissions are good

i searched sth about this a lot but solutions doesnt help so much.I tried to upgrade redmine to 2.6.5 on my FreeBSD but i have 403 error.
apache error log:
[autoindex:error] AH01276: Cannot serve directory
/usr/local/www/redmine/public/: No matching DirectoryIndex (none)
found, and server-generated directory index forbidden by Options
directive
my httpd conf:
<VirtualHost example.com:80>
DocumentRoot "/usr/local/www/redmine/public"
ServerName example.com
FastCgiServer /usr/local/www/redmine/public/dispatch.fcgi -idle-timeout 120 -initial-env RAILS_ENV=production -initial-env PATH=/usr/local/bin -processes 2
<Directory "/usr/local/www/redmine/public">
AddHandler fastcgi-script fcgi
Order allow,deny
Allow from all
AllowOverride all
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi
</Directory>
ErrorLog /logs/error.log
</Virtualhost>
i have to say: if i add +Indexes in Option i see files in my browser, so i guess premissions are good.
Anyone can give me any hint?
thanks in advance 4 your help
In my situation the problem was caused by a bug in the apache module ModAutoIndex. Disabling the module did the trick.
See https://serverfault.com/a/731859
Disabling the module auto index (which is the cause of the wrong behaviour, will prevent the error.
#LoadModule autoindex_module modules/mod_autoindex.so
Phusion will address the issue in the realase of Passenger 5.0.22 before Apache 2.5.0 will be released.
I suffered the same issue on my ArchLinux installation with Apache 2.4 and Redmine 2.6.5. Instead of fcgi I use the Phusion Passenger web application server but I always ended up on a 403 Forbidden page like you when accessing the server.
With the +Indexes option I also got the contents of the Redmine public directory on the browser.
When using webrick or passenger directly to host Redmine everything was fine. That's how you can verify your Redmine is not corrupted somehow. From the Redmine root directory run:
bundle exec ruby scripts/rails server -e production
Since I'm using RVM to manage ruby versions and gemsets on the system I can also tell you that the behavior is not related to ruby ( I tried every version from 1.8.x to 2.2.x without any change ).
In the end I substituted Apache with nginx 1.8.0 (stable release) and got Redmine back to work. So with passenger it's quite easy to get rolling. Just run
gem install passenger
so you get the passenger package. And then compile nginx with the passenger module using
passenger-install-nginx-module
You'll get an automated dialog that downloads nginx and compiles it with the appropriate config. By default it will be installed to /opt/nginx
On ArchLinux you would rather use the ABS to get the PKGBUILD and add the following to the configure part
--add-module=$(passenger-config --nginx-addon-dir) \
That way you also get the systemd unit-file to start and stop nginx.service
Last but not least here's the nginx config I use to run Redmine:
server {
listen 80;
server_name redmine.example;
root /usr/share/webapps/redmine-2.6.5/public;
passenger_base_uri /;
passenger_app_root /usr/share/webapps/redmine-2.6.5;
passenger_document_root /usr/share/webapps/redmine-2.6.5/public;
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-1.9.3-p551#redmine/wrappers/ruby;
}
Using another webserver may be a daunting step but it took me less than 2 hours to get Redmine up and running with nginx compared to nearly 2 days of wasted time to figure out why the heck Apache didn't serve the webapp any more.

setting up passenger: keeps showing apache default page instead

I am trying to get passenger to work but i keep seeing the apache default page instead. I am using centos 6.3 on an inmotion VPS. Here is what I've done so far:
gem install passenger.
rvmsudo passenger-install-apache2-module
pasted the following code into /usr/local/apache/conf/includes/post_virtualhost_global.conf (this gets loaded into httpd.conf)
LoadModule passenger_module /home/username/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /home/username/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.17
PassengerRuby /home/username/.rvm/wrappers/ruby-1.9.3-p194/ruby
<VirtualHost 123.123.123.123:80>
ServerName http://XXXXXX.inmotionhosting.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/username/rails/current/public
<Directory /home/username/rails/current/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
edit: not sure why this isnt formatting properly. its lined and tabbed fine in the text editor.
in etc/hosts there is the line:
123.123.123.123 XXXXXX.inmotionhosting.com XXXXXX
i restarted apache via sudo service httpd restart in /etc/init.d
still shows apache default page
Any ideas? thanks
I stumbled upon this 1 year old post for the similar problem but none of the comment worked for me. So I'm just adding my 2 cents for those who are looking for some help.
If you are seeing Apache default page, it means that phusion passenger is probably not running. You might have seen a warning message when you started/stopped/restarted the apache server that says the phusion passenger module is already loaded, skipping.
So Apache has skipped the most recent LoadModule line you added in the conf file.
Then check the error.log which is in the directory set for error log in apache config file. (httpd.conf for centos)
In my case, it was complaining that it couldn't find the watchdog in the directory set in PassengerRuby. This confirms that the passenger module loaded is NOT what I just added. This might have happened because I am using RVM now but also installed an old version of Passenger a while ago as a root. So I looked at the config.d directory under Apache root, there was a file "passenger.conf" that was loading the old version of Passenger.
I deleted the file, kept the new LoadModule as is - copied from the instruction Phusion Passenger gave me while installing apache2-module, restarted the apache server, no warning message, and passenger worked.

get 404 with passenger and rails

I'm trying to run a rails app on a shared hoster.
I create the app in the directory /home/rails_projects/jens_blog and the document root is /home/www/jens_blog.
In the /home/www/jens_blog dir is a symlink public -> /home/rails_projects/jens_blog/public/
I created a scaffold posts. But when i run the mydomain/ or mydomain/posts in the browser I get always an 404 error.
File does not exist: /home/www/jens_blog/public/posts
<VirtualHost ip.port>
ServerName www.mydomain.de
ServerAdmin webmaster#www.mydomain.de
DocumentRoot /home/www/jens_blog/public
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/bin/ruby
PassengerDefaultUser myuser
PassengerAnalyticsLogUser myuser
CustomLog /home/log/access_log mesos2
<Directory "/home/www/jens_blog/public">
Allow from all
Options -MultiViews
Options FollowSymLinks
</Directory>
</VirtualHost>
if I put a index.php file into the /home/rails_projects/jens_blog/public/ dir the file content will be show.
Can anybody help me?? I am desperated.
I have only a shared web hosting.
Update: I added "PassengerResolveSymlinksInDocumentRoot on" to the apache config. But now I get Exception LoadError in PhusionPassenger::Rack::ApplicationSpawner (no such file to load -- bundler)
:-((
Cheers
Jens
My question was quite similar to yours Deployed rails site on ec2 using capistrano, but it doesn't show up on the browser, here is the site -> http://passionate4.net/
I would say place your site in this directory /var/www/myapp/public.
Use these settings.
ServerName www.passionate4.net
DocumentRoot /var/www/capi_app/current/public
RailsEnv production
Allow from all
Options -MultiViews
I have written couple of blogs on how to successfully deploy the site on Ubuntu. I believe you problem is quite similar to mine. http://recipe4developer.wordpress.com/