How to config apache to run Django (mod_WSGI) and Rails (Passenger) - ruby-on-rails

I was running only my django applications with apache2 mod_WSGI but now I want to add Rails (Passenger) applications to the same server. I installed Passenger and it's working fine.
After searched while I found a way to run it on www.myserver.com so I have:
www.myserver.com -> rails app
www.myserver.com/app1 -> django app 1
www.myserver.com/app2 -> django app 2
The problem is I don't know how to config httpd.conf file to run for example: www.myserver.com/myrailsapp -> rails app.
I'm on Ubuntu Server 10.04 and Apache2
httpd.conf:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRuby /usr/bin/ruby
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/
Include /etc/apache2/rails.conf
<VirtualHost www.myserver.com:80>
ServerName www.myserver.com.com
WSGIScriptAlias /hello /home/user/django/projects/hello/hello.wsgi
<Directory /home/user/django/projects/hello>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /app1 /home/user/django/projects/app1/app1.wsgi
<Directory /home/user/django/projects/app1>
Order allow,deny
Allow from all
</Directory>
Alias /static/admin /home/user/django/src/django/contrib/admin/media
ErrorLog /home/usero/django/projects/logs/error.log
CustomLog /home/user/django/projects/logs/access.log combined
</VirtualHost>
At line: Include /etc/apache2/rails.conf
DocumentRoot /home/user/ruby/projects/redmine/public
<IfDefine PASSENGER>
RailsBaseURI /redmine
</IfDefine>
This include (rails.conf) is what made the Rails app run but I can put anything on 'RailsBaseURI /redmine' but nothing changes.
Q: How can I do www.myserver.com/redmine redirects to /home/user/ruby/projects/redmine/public ?
Any help is welcome.
Thanks.

Use passenger for the rails support for Apache and
apache2-mod-python ( sudo apt-get install apache2-mod-python ) for the django part.
It worked with me ;)

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>

Rails app on apache, passenger lists the directory instead of showing login page?

I am deploying a ruby-on-rails application.
I have configured apache and passenger and the http server is listening on port 80.
When I try to access the home page using the browser, I simply get a list of files and directories instead of the home page.
Following are snippets from the apache config.
/etc/apache2/apache2.conf
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
/etc/apache2/httpd.conf
LoadModule passenger_module /home/user1/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.27/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/user1/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.27
PassengerDefaultRuby /home/user1/.rvm/gems/ruby-2.3.0/wrappers/ruby
</IfModule>
/etc/apache2/sites-available/ubuntuvm-4.conf
<VirtualHost *:80>
ServerAdmin admin#ubuntuvm-4.com
ServerName ubuntuvm-4
ServerAlias www.ubuntuvm-4.com
DocumentRoot /home/user1/www/myapp/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What is going wrong?
Could it be that I am trying to access the page via the ip address
http://192.168.0.12?
If you want me to put any other config, please shout.
try to copy the content of the file /etc/apache2/sites-available/ubuntuvm-4.conf
to /etc/apache2/sites-enabled/ubuntuvm-4.conf
cp /etc/apache2/sites-available/ubuntuvm-4.conf /etc/apache2/sites-enabled/ubuntuvm-4.conf
You need to create your config like this
<VirtualHost *:80>
ServerName ubuntuvm-4
<Location /home/user1/www/myapp/public>
PassengerBaseURI /
PassengerAppRoot /home/user1/www/myapp
</Location>
DocumentRoot /home/user1/www/myapp/public
<Directory /home/user1/www/myapp/public>
AllowOverride all
RailsEnv production
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
I had the same problem trying to deploy a 4.2.1 Rails app on Ubuntu 12.04 using Ruby 2.3.2 (RVM because .deb packaged version is damn too old !!) Apache 2.2 and Passenger 5.0.4 (.deb).
Well, after wasting days to try to figure out why passenger wouldn't start (I did this a thousand times, it always worked), I realized it was only because Passenger couldn't print its logs anywhere. So, if you already tried everything you read on forums, just try to add a path to a log file in your apache configuration :
PassengerLogFile /var/log/passenger.log
and it worked like magic. Hope this helps.

Deploying a Rails App to GCE with Passenger, but only seeing the app's file directory

I am using the Google Cloud Engine ruby stack, which uses RVM and Passenger on Debian 7. After following the Passenger configuration manual, I am only seeing a directory of the app's files when I navigate to the server root.
Here's the /etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName http://130.211.149.208
DocumentRoot /var/www/myapp
<Directory /var/www/myapp>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
Figured it out. The problem was /var/www/myapp should be /var/www/myapp/public

Ruby: Problem using passenger

i first installed mod_ruby on my debian and afterwards ( after figuring out that it was too slow ) i wanted to chagne to passenger for my apache
Now i've got the problem, that the passenger is successfully loaded by the apache, but is not used, even though i configured everything correctly, like:
<VirtualHost *>
ServerAdmin webmaster#localhost
ServerName xyz
DocumentRoot /var/www/vhosts/default/htdocs/
RailsBaseURI /rails
</VirtualHost>
Instad of the the passenger the cgi - module is used for displaying rails-apps... ( if i unload the cgi.conf and cgi-load from the "sites-enabled" folder, it's not working anymore... on the other hand it still works if i unload the passenger.load and passenger.conf files... )
So, how can i force the apache to use the passenger to display rails sites?
Assuming you have passenger installed and configured correctly with Apache ... Your DocumentRoot needs to point at the public directory of your rails app. Here's a working VirtualHost directive:
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot "/path/to/myapp/public"
RailsEnv development
<directory "/path/to/myapp/public">
Order allow,deny
Allow from all
</directory>
</VirtualHost>
Beforehand, also make sure that named virtual hosts are turned on:
NameVirtualHost *:80
And also that you actually have the passenger model configured correctly. For example:
LoadModule passenger_module /path/to/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /path/to/ruby/gems/1.8/gems/passenger-2.2.5
PassengerRuby /path/to/bin/ruby
Did you reconfigure the relative_url_root in your rails application? For example, in config/environment.rb:
config.action_controller.relative_url_root = "/rails"

Resources