Deploying two different Rails app with different Ruby versions - ruby-on-rails

I have two different Rails apps.
One is using Ruby 1.9.3 and another one is using 2.0. I need to host both of these apps on the same Apache2 server.
I tried somthing like this:
Listen 81
Listen 82
LoadModule passenger_module /home/admin1/.rvm/gems/ruby-1.9.3-p194/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/admin1/.rvm/gems/ruby-1.9.3-p194/gems/passenger-4.0.53
PassengerRuby /home/admin1/.rvm/gems/ruby-1.9.3-p194/wrappers/ruby
</IfModule>
<VirtualHost *:81>
ServerName test.ap_live_streaming.com
RailsEnv test
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/admin1/app/current/ap_live_streaming/public
<Directory /home/admin1/app/current/ap_live_streaming/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
LoadModule passenger_module /home/admin1/.rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/admin1/.rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.53
PassengerDefaultRuby /home/admin1/.rvm/gems/ruby-2.0.0-p451/wrappers/ruby
</IfModule>
<VirtualHost *:82>
ServerName test.ap_live_streaming.com
RailsEnv test
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/admin1/app/current/do_dashboard/public
<Directory /home/admin1/app/current/do_dashboard/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
But, while restarting the Apache2 server, it's showing:
[Mon Nov 03 14:59:02.547078 2014] [so:warn] [pid 15821] AH01574: module passenger_module is already loaded, skipping
There are no issues with the virtualhost. But I am little worried about the loadmodules.

Related

Freebsd 10.1 / Ruby on Rails / Apache 2.4 / Phusion Passenger : client denied by server configuration

I can't get passenger to work with apache24 on freebsd 10.1
If I place the virtualhost below into my httpd.conf not only does a request for the virtualhost return 403 forbidden but also the server's hostname documentroot which is just index.html file without rails returns 403 forbidden also the httpd-error.log only says client denied by server configuration.
I assume passenger is failing to rewrite the requests from /public to /app/views/index.html.erb because I didn't put any html files in
/public Already installed mod_fastcgi but responses are still 403 forbidden
This is the tail of my httpd.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/2.1/gems/passenger-5.0.18/buildout/apache2/mod_passenger.so
LoadModule fastcgi_module libexec/apache24/mod_fastcgi.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.1/gems/passenger-5.0.18
PassengerDefaultRuby /usr/local/bin/ruby21
</IfModule>
# Virtual hosts
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /usr/home/myusername/websites/myrailsappname/public
<Directory /usr/home/myusername/websites/myrailsappname/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Include etc/apache24/Includes/*.conf
Apache 2.4 has different allow/deny rules:
http://httpd.apache.org/docs/2.4/upgrading.html#run-time
You will want to update your rule:
<Directory /usr/home/myusername/websites/myrailsappname/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
to something like:
<Directory /usr/home/myusername/websites/myrailsappname/public>
AllowOverride all
Options -MultiViews
require all granted
</Directory>

Apache Passenger configuration issue

I've been trying for days to get a rails app to run under Passenger on Bluehost, but with no luck. Going to my subdomain where I'm hoping this will run, I'm only getting a directory listing with cgi-bin and public subdirectories. No execution of the rails app.
httpd.conf includes:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.6
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby
</IfModule>
and
<VirtualHost 162.144.138.43:80>
ServerName secure.xxxxx.com
ServerAlias www.secure.xxxxx.com
DocumentRoot /home/diamoou1/public_html/securefinance
ServerAdmin webmaster#secure.xxxxx.com
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/secure.xxxxx.com combined
CustomLog /usr/local/apache/domlogs/secure.xxxxx.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User diamoou1 # Needed for Cpanel::ApacheConf
UserDir enabled diamoou1
<IfModule mod_suphp.c>
suPHP_UserGroup diamoou1 diamoou1
</IfModule>
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup diamoou1 diamoou1
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RUidGid diamoou1 diamoou1
</IfModule>
ScriptAlias /cgi-bin/ /home/diamoou1/public_html/securefinance/cgi-bin/
<Directory /home/diamoou1/public_html/securefinance>
Options -MultiViews
AllowOverride All
</Directory>
</VirtualHost>
In /home/diamoou1/public_html/securefinance/public I have the .htaccess file:
<IfModule mod_passenger.c>
Allow from all
Order Deny,Allow
Options +FollowSymLinks -SymLinksIfOwnerMatch -MultiViews
PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
RackBaseURI /
SetEnv GEM_HOME /home/diamoou1/ruby/gems
</IfModule>
Temporarily putting a bad line in the .htaccess file will give the expected error in the log, so apparently apache is reading the .htaccess file.
I suspect the problem might be in RackBaseURI. I installed Passenger as root. RackBaseURI resolves to /root and there is a /root/public_html directory, although apache is serving up the /home/diamoou1/public_html/securefinance directory (where the rails app actually resides). I don't know how to change that variable or it that's really the problem. PassengerBaseURI is the same.
What do I do to fix this?????
This may help you : https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#_tutorial_example_writing_and_deploying_a_hello_world_rack_application
Here is the example configuration provided by Phusion Passenger :
<VirtualHost *:80>
ServerName www.rackexample.com
DocumentRoot /webapps/rack_example/public
<Directory /webapps/rack_example/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
DocumentRoot and Directory should point to the public folder of your rails application not the root.
You should change :
...
DocumentRoot /home/diamoou1/public_html/securefinance
...
<Directory /home/diamoou1/public_html/securefinance>
...
to :
...
DocumentRoot /home/diamoou1/public_html/securefinance/public
...
<Directory /home/diamoou1/public_html/securefinance/public>
...

multiple rails app in apache using passenger on centos

I have been following this guide on how to run a rails app in an apache server. I have successfully made it work but with only 1 rails app running. I tried editing the httpd.conf with 2 virtual hosts.
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.42
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.1.1/ruby
RackEnv development
<VirtualHost *:3000>
ServerName ***.***.***.***
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/testapp/public
<Directory /var/www/html/testapp/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:3001>
ServerName ***.***.***.***
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/testapp2/public
<Directory /var/www/html/testapp2/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
but it seems only port 3000 is working.
You'll need to make sure you have the other server set up on port 3001
Port
The problem you'll have is that you're capturing the same request (to same domain / IP), except listening on different ports. If you want to access the different sites, therefore, you have to access by the ports you define.
#app1 -> ***.***.***.***:3000
#app2 -> ***.***.***.***:3001
This should give you the ability to access your Rails apps respective to your apache implementation.
--
VirtualHosts
If I were you, I'd either create a virtualhost with a directory setup:
/etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName [ip]
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /apps/public
#Other App
Alias /app1 /apps/app1/public
<Location /reach>
PassengerAppRoot /apps/app1/public
RackEnv production
RackBaseURI /app1
</Location>
#Other App
Alias /app2 /apps/app2/public
<Location /apps>
PassengerAppRoot /apps/app2/public
RackEnv production
RackBaseURI /app2
PassengerFriendlyErrorPages off
</Location>
</VirtualHost>
This will give you a much simpler way to handle the incoming requests:
***.***.***.*** -> IP index
***.***.***.***/app1 -> application 1
***.***.***.***/app2 -> application 2
I'd be much more tempted to use the above setup than your own.
Further, you may also wish to actually deploy separate virtual hosts for your applications. The above example details how you'd introduce different directories for your different apps - if you'd prefer to create different virtualhosts, here's what you can do:
#etc/apache2/sites-available/default (standard site - I'd recommend static)
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#etc/apache2/sites-available/app1
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias yourdomain.com
DocumentRoot /apps/app1/public
<Directory /apps/app1/public>
Allow from all
Options -MultiViews
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Don't forget to symlink these to your /etc/apache2/sites-enabled folder:
> $ ln -s /etc/apache2/sites-available/app1 /etc/apache2/sites-enabled/app1

How to deploy Rails app on subdomain root with Apache and Passenger

I have working Rails app on sub-uri redmine.example.org/redmine and I want it on redmine.example.org
/var/www/work/redmine.src is approot
/var/www/work/redmine is symlink to /var/www/work/redmine.src/public
<VirtualHost *:80>
DocumentRoot /var/www/work
ServerName redmine.example.org
ErrorLog /var/log/apache2/redmine-error_log
CustomLog /var/log/apache2/redmine-access_log combined
<Directory /var/www/work/redmine>
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
</Directory>
RackBaseURI /redmine
<Directory /var/www/work/redmine.src>
Options -MultiViews
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I tried many combination and googled hours, but nothing works.
How should I change this config to deploy redmine on subdomain root?
Thanks in advance.
Well, it was easier, than I supposed.
When I read the manual again and again I found solution:
link to manual
Now my config file looks like this:
<VirtualHost *:80>
DocumentRoot /var/www/work/redmine.src/public
ServerName redmine.example.org
<Directory /var/www/work/redmine.src/public>
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Another way to deploy sub-uri app, might work for you too:
<VirtualHost *:80>
ProxyPass /sub_uri/ http://localhost:8000/sub_uri/
DocumentRoot /main_app/public
<Directory /main_app/public>
...
</Directory>
</VirtualHost>
<VirtualHost *:8000>
DocumentRoot /sub_uri/public
<Directory /sub_uri/public>
...
SetEnv RAILS_RELATIVE_URL_ROOT /sub_uri
</Directory>
</VirtualHost>
I installed Redmine 3.3.1 on a Debian 9.0 Stretch server using the packages provided by the distribution itself (Apache + Redmine + Ruby + Rails + Passenger + MariaDB) more or less following those guides:
http://www.redmine.org/projects/redmine/wiki/RedmineInstall
http://www.redmine.org/projects/redmine/wiki/InstallRedmineOnDebianStableApacheMysqlPassenger
I would like to leave www.example.org "for Apache" and redmine.example.org "for Redmine", so I ended up with the following setup.
I left /etc/apache2/sites-available/000-default.conf untouched and created a file named redmine.conf inside that same folder:
<VirtualHost *:80>
ServerName redmine.example.org
DocumentRoot /usr/share/redmine/public
PassengerRuby /usr/bin/ruby
<Directory /usr/share/redmine/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Then, I've linked it to the sites-enabled folder and restarted Apache:
# ln -s /etc/apache2/sites-available/redmine.conf /etc/apache2/sites-enabled/redmine.conf
# systemctl restart apache2
To set up that virtual host, I followed the directions here:
Deploying a Ruby application on Passenger + Apache
Deploying an app to a virtual host's root
https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/#deploying-an-app-to-a-virtual-host-s-root

Default page in Apache + Passenger + Rails 3.1

In the end of the apache2.conf i added :
LoadModule passenger_module /home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11
PassengerRuby /home/rusik/.rvm/wrappers/ruby-1.9.2-p290/ruby
ServerName localhost
<VirtualHost *:80>
ServerName sample.app
DocumentRoot /home/rusik/work/ruby/sample_app/public
</VirtualHost>
So , when i restarted apache
sudo apachectl restart
I got default apache page ,not rails project default page ,why ?
The default file in /etc/apache2/sites-enabled/000-default , where are default virtual hosts i didn't change .
Have you tried put
<Directory /home/rusik/work/ruby/sample_app/public>
AllowOverride none
Options -MultiViews
</Directory>
within and restart the server?
Also add... Options FollowSymLinks
<Directory ... >
...
Options FollowSymLinks
</Directory>

Resources