apache passenger deploy rails only show directory - ruby-on-rails

I've looked all google results, and non of them helps:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/site/example.com/current/public
<Directory /var/www/site/example.com/current/public>
Options -Multiviews
Allow from all
</Directory>
</VirtualHost>
and as you can see, the app is deployed into:
/var/www/site/example.com/current/public
though Capistrano, where my app don't have an index page, but rails suppose to use the root I setup in the route file instead
But when I enter the url of, it only shows the public directory with its
As for the logs:
NO log in the rails log directory
No log for all the apache

I later found the issue is I shouldn't sudo passenger-install-apache2-module, I should rvmsudo passenger-install-apache2-module
It is annoying since there is no hint from either passenger or apache telling that the passenger seems wasn't running, even the apache config has included passegner module and restart ok

Related

Deploy Ruby to Production with Apache and Passenger

Background:
I have my web app running on unbuntu 18.04 + Apache & Passenger. I am using ruby 2.5 and rails 5.2. Right now the the project is running in development env.
Not sure if more info is needed so please ask. Thanks for anyone who can help. I am considering switching to NGINX and using ruby gem cap.
Question:
I am trying to configure Passenger to run my rails app in Production, but I can only make it run in development env. When I try to make changes for production env, it just stops working...
after changes I am running
sudo apache2ctl restart
sudo service apache2 restart
My .conf file
<VirtualHost *:80>
ServerName dev1.example.net
#ServerAlias dev1.example.net
#ServerAdmin webmaster#localhost
DocumentRoot /home/augustus/dev/xxx/public
RailsEnv development
PassengerRuby /home/augustus/.rbenv/versions/2.5.0/bin/ruby
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/augustus/dev/xxx/public >
# Allow from all
AllowOverride all
Options -MultiViews
# Options FollowSymLinks
Require all granted
</Directory>
:What I have tried
I am setting the RailEnv to 'production'
I have also reinstalled the repo completely
I read over other stack overflow post's about this. I am not having issues getting it running, but just putting it in production. When I visit the webpage (www.example.com), it gives me the "we're sorry, but something went wrong"..
the most helpful link was
OS X: Development & Production Deployment for RoR with Apache and Passenger
&& passenger dox
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/digital_ocean/apache/oss/bionic/deploy_app.html

Ruby on rails application shows files index instead of the app

I would like to deploy a Ruby on Rails application on the web, and for that matter I have used/deployed the following tools:
Capistrano, to deploy the app files to the target location
The Phusion Passenger module for Apache
I have enabled the Passenger module through sudo a2enmod passenger. I have also installed the passenger gem through the gem installer, and added it to the Gemfile of my rails app.
I have then created an Apache virtual host for the app 'myapp'.
myapp.conf
Alias /myapp /var/www/myapp/current/public
<VirtualHost *:80>
DocumentRoot /var/www/myapp/current/public
SetEnv SECRET_KEY_BASE 592da***************************************
<Directory /var/www/myapp/current/public>
PassengerEnabled on
PassengerResolveSymlinksInDocumentRoot on
PassengerAppRoot /var/www/myapp/current
PassengerAppType rack
PassengerStartupFile config.ru
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
The virtual host work, but when I access the URL in a web browser, it shows the files index in /var/www/myapp/current/public instead of the actual app. The reason for this seems to be that passenger is not started, but I can't figure out why. I have tried to tweak the myapp.conf file to help apache and passenger detect the app, but without success.
Could anyone help me fix this? Thanks in advance.
Additional info: the app is deployed on a Raspberry Pi 3 with Raspbian Jessie as OS.
Try this .This is for sub uri deployment.Error is because PassengerRuby path has not been mentioned. Also go through this link
https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/.
Alias /myapp /var/www/myapp/current/public
<VirtualHost *:80>
SetEnv SECRET_KEY_BASE 592da***************************************
PassengerRuby /path-to-ruby /* replace this with your ruby path
<Location /myapp>
PassengerBaseURI /myapp
PassengerAppRoot /var/www/myapp/current
PassengerEnabled on
</Location>
<Directory /var/www/myapp/current/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>

Why does a Rails Application run properly from a port but not from a subdomain?

Here is the content of my /etc/apache2/sites-available/default file
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domain.com
# !!! Be sure to point DocumentRoot to ('public')!
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName a.domain.com
# !!! Be sure to point DocumentRoot to ('public')!
DocumentRoot /home/user/A/public
<Directory /home/user/A/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName b.domain.com
# !!! Be sure to point DocumentRoot to ('public')!
DocumentRoot /home/user/B/public
<Directory /home/user/B/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName c.domain.com
# !!! Be sure to point DocumentRoot to ('public')!
DocumentRoot /home/user/C
<Directory /home/user/C/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
The intention is to "link" the subdomain names (such as a.domain.com) to a Rails application running on a specific port (with multiple low intensity Rails application on the same server). The configuration shown above works to redirect to the appropriate static page AND/OR rails application, except for one of them which has a problem:
The problematic Rails application runs properly when accessed via:
domain.com:port (or domain.com:4444 )
however when attempts to access the same Rails application via:
c.domain.com (subdomain linked to the directory where the Rails app lives)
it throws this error:
https://github.com/net-ssh/net-ssh (at master) is not yet checked out. Run `bundle install` first. (Bundler::GitError)
To be clear, the same Rails application WORKS properly when accessed from domain.com:port but fails with c.domain.com
Since one of the Rails applications in the collection works and another fails, I find this very puzzling. So far I cannot find anything like this in my searches.
Questions and suggestions are very welcome.
Thank you,
~ Allen
NEWS:
I'm still reading documentation in an attempt to understand why accessing the rails application by port or by sub domain (domainname.com:port .vs. sub.domainname.com) behaves differently. However, I did determine making apache the owner of the directory structure helped get access by sub domain working. (apache user = www-data )
chown -R www-data:www-data /home/user/app
resolved the issue for one of the rails apps. There was also a .htaccess file in the public directory which had to be removed and the need to use this version of the bundle command:
bundle install --path vendor/bundle
that was not needed for the other application running on a sub domain.
It seems I have technically solved the puzzle, however I still don't understand the why it was necessary for one application and not for another.
Are your document roots all symlinks to the same RAILS_ROOT directory? Or is there a copy of the app in each of the document roots?

Ruby on Rails using Apache 2 with passanger "mod_rails" kind of working but not really

Alright I'll try and make this as short as possible. Currently I'm running OS X (10.8.4) with the default Apache 2 install. I installed passenger using home brew. I went through the setup wizard, and mod_rails appears to be working because I see this log statement, [ 2013-09-03 01:33:21.3513 34289/0x7fff71bf9180 agents/Watchdog/Main.cpp:642 ]: All Phusion Passenger agents started! in the /var/log/apache2/error_log file.
When I navigate to localhost in a web browser I get the following, however the rails.png file isn't showing.
The access_log for Apache 2 looks like the following,
http://pastie.org/8293413#
The httpd.conf file,
# Added by Chris - 27AUG13
LoadModule passenger_module /Users/capin/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.14/buildout/apache2/mod_passenger.so
PassengerRoot /Users/capin/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.14
PassengerDefaultRuby /Users/capin/.rbenv/versions/2.0.0-p247/bin/ruby
<VirtualHost *:80>
ServerName lucky
# Be sure to point DocumentRoot to 'public'!
DocumentRoot /Library/WebServer/Documents/simple_cms/public
<Directory /Library/WebServer/Documents/simple_cms/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
So for whatever reason the rails.png file isn't loading :/
That's because you're looking at a static file, public/index.html. Phusion Passenger's static asset acceleration feature makes Apache serve that file instead of Rails, so the request never reaches Rails.
Well I figured out why the rails.png file wasn't loading. It was because the rails application was trying to connect to a database, and I had not created the database in MySQL. I was getting the following error in my Apache error log file, error_log
http://pastie.org/8295425
So I created the MySQL database according to what was specified in the database.yml and then I reloaded the localhost page, and whala,

VirtualHost problem with passenger (mod_rails)

I'm at my wit's end here with virtual hosting. I'm trying to install redmine and it works with the webrick test server, but when I tried to use passenger (mod_rails) to host and go to the address I specified when in the virtualhost part of my apache config file nothing happens. Here is the relavent section of /etc/httpd/conf/httpd.conf where I try to set up the virtual host:
<VirtualHost *:80>
SetEnv RAILS_ENV production
ServerName redmine.MYSITE.com:80
DocumentRoot /opt/redmine-1.0.5/public/
<Directory /opt/redmine-1.0.5/public/>
Options -MultiViews
Allow from all
AllowOverride none
</Directory>
However, when I got to redmine.MYSITE.com:80 nothing happens, I just get our normal home page. I have no idea what the problem is, any help our guidance would be greatly appreciated. If you need any other information, please tell me and I'll provide it.
It took me a while to get Redmine running under Passenger. This is what I have
Install passenger:
passenger-install-apache2-module
Edit Apache confg file:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11
PassengerRuby /usr/bin/ruby
Create a new directory in the default server:
<Directory>
/webserver_root/html/redmine
RailsBaseURI /redmine
AllowOverride all
Options -MultiViews
</Directory>
Lastly, make a link to the physical directory where your ruby apps live (ie NOT under /html or whatever directory you serve most Apache pages from. This MUST be a link to redmine's public subdirectory)
ln -s /webserver_root/ruby_apps/redmine/public /webserver_root/html/redmine
So Apache now tries to show all the public pages as normal, but all other pages get routed through passenger. You access it as a subfolder - eg. http://mywebserver/redmine
Your VirtualHost *:80 directive must be matched by a corresponding NameVirtualHost *:80 earlier in your config.
You can ask apache what it makes of your vhosts with the -S switch. Of course, the name of your server binary depends somewhat on how it was installed and on what OS/Distro.

Resources