Running same Ruby application in multiple environments - ruby-on-rails

I'm doing local development of a Ruby application, and want to setup both a production and development environment. I intend to use production locally almost like a staging server, to demonstrate the current state of the codebase to my client. However, I want to run an actual development environment with different settings for my personal use.
I intend to use virtual hosts to distinguish the two sites. No matter how I try to change settings in Apache + Passenger, they both run in the same environment though (either both production or both development). How can I make the same codebase run in different environments for different virtual hosts?
/etc/apache2/sites-available/app.conf:
<VirtualHost *:80>
ServerName app.local
ServerAlias app.example.com
DocumentRoot /code/sites/app/public
RailsEnv production
RackEnv production
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
LogLevel debug ssl:debug
ErrorLog ${APACHE_LOG_DIR}/app.error.log
CustomLog ${APACHE_LOG_DIR}/app.access.log combined
</VirtualHost>
/etc/apache2/sites-available/app-dev.conf:
<VirtualHost *:80>
ServerName app.dev.local
DocumentRoot /code/sites/app_dev/public
RailsEnv development
RackEnv development
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
LogLevel debug ssl:debug
ErrorLog ${APACHE_LOG_DIR}/app-dev.error.log
CustomLog ${APACHE_LOG_DIR}/app-dev.access.log combined
</VirtualHost>

Give each app vhost a different PassengerAppGroupName so that Phusion Passenger treats them as different apps.

This is a much easier solution to your problem. https://ngrok.com/ It won't run as fast as it would if you set everything up, but it's infinitely easier to set up.

Related

Apache + Passenger Rails app failing with a 403 error

I currently have a rails app that works locally but at the moment of deploying the app i'm having an error configuring the server.
I followed the steps here, and i'm stuck on step 6. Instead of seeing the rails webpage i got
Inside /etc/apache2/sites-available/tesis.conf i got
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/tesis/public
RailsEnv development
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/tesis/public">
Options -MultiViews
Require all granted
Allow from all
</Directory>
And the rails app is located at /var/www/html/tesis/public, so that makes sense, but the odd thing is that debugging the apache error logs (/etc/apache2/sites-available/tesis.conf) i see:
[client 143.244.50.172:44448] AH01630: client denied by server configuration: /home/deploy/tesis/public/config
Why apache is going to that path instead of the one i specify on the configuration file?

Redmine in Apache shows Blank Page

I've just tried to configure Redmine on my Apache server, as folows:
Files in /var/www/redmine.my.domain
In /etc/apache2/sites-available/redmine.my.domain.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName redmine.my.domain
ServerAdmin webmaster#localhost
DocumentRoot /var/www/redmine.my.domain/public/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/redmine.my.domain/public>
Options Indexes ExecCGI FollowSymLinks
Order allow,deny
Allow from all
AllowOverride all
Options Indexes FollowSymLinks MultiViews
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
It only shows a blank page. Does anyone know what may be missing?
Redmine is RoR (Ruby on Rails) application, for usage and installation, official wiki should be followed since there are multiple steps and ways to run it on different platforms. Cick here and find the best way for your case.
In order to run it via Apache you must either run it as CGI/FCGI which is not very common way.
Or to run it via PhusionPassenger Apache module or PhusionPassenger standalone.
One common way to run it is via some Ruby app server like Puma, Unicorn, Webrick or Thin, then Apache or Ngnix reverse proxy it.
As stated earlier, various methods to run it, depending upon platform are described in official wiki.

Images are not loading on production

I'm deploying a Rails app to Digitalocean. I'm working with Apache and Passenger. I was able to run my app locally in production and worked fine. I had the same problem on localhost but did the following things to make it work. Locally I work with Webrick server and in Ubuntu with Apache.
Installed these gems:
therubyracer
execjs
I added this to production.rb
config.serve_static_files = true
config.assets.compile = true
config.assets.precompile = ['*.js', '*.css']
Then I did
RAILS_ENV=production bundle exec rake assets:precompile
I tried the same for production in Ubuntu and everything seems fine but the images.
This is what I have in /etc/apache2/sites-available/metalmind.com.co.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin something#hotmail.com
ServerName metalmind.com.co
ServerAlias www.metalmind.com.co
DocumentRoot /home/luisjar/Metalmind_2/public
<Directory "/home/luisjar/Metalmind_2/public">
Options All
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I appreciate any help here.
For images to load in production , you need to check certain things -
1) What's the url being generated where you see no image loaded (Use firebug to see the url path)
2) Where are you storing your images , is it under images or under public folder .
3) Have you precompiled you assets for production using this command (rake assets:precompile RAILS_ENV=production)
Also , in cases like these logs are quite helpful too .

Rails 3 + passenger conf file

I have been trying to install a rails app on a box that originally was used for multiple php applications. I installed passenger and created a conf file but I am confused about how it all works together.
What should my ServerName be if i want to access a Rails app? The box is a debian squeeze running apache2 with passenger module installed. Below is my conf file. I currently have to go to xxx.xxx.xxx.xxx/leoadmin/public to get the application to run properly. I have the following htaccess in the public directory. Which I think is unnecessary if my conf file is configured correctly.
I think my main issue is the misconfiguration of the conf file. I believe the conf file is being loaded but i don't understand why i still need the htaccess for me to see any action.
.htaccess
#PassengerEnabled On
PassengerAppRoot /var/www/leoadmin/
#Options -MultiViews
#PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
#RackBaseURI /var/www/leoadmin
vhost config
<VirtualHost *>
ServerName leoadmin
DocumentRoot /var/www/leoadmin/public
<Directory /var/www/leoadmin/public>
Allow from all
</Directory>
Alias /leoadmin /var/www/leoadmin/public
<Location /leoadmin>
SetEnv RAILS_RELATIVE_URL_ROOT "/leoadmin"
PassengerAppRoot /var/www/leoadmin
</Location>
ErrorLog /var/log/apache2/leoadmin-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/leoadmin-access.log combined
</VirtualHost>
I had nothing but pain and more pain trying to get this sorted a few months back, my configuration allows me to do sub URIs, so I'm not sure if that's what you want, but it'll be along these lines. I've never needed a .htaccess file for this setup:
NameVirtualHost *:80 <VirtualHost *:80>
ServerName www.test.co.uk
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
RailsEnv development
<Directory /web/rails_projects/test/>
Options -MultiViews
</Directory>
For me /web/rails is a root directory, from there I have a number of symlinks to my /home/ directory where I store my projects. ServerName is whatever qualified name you're using for the machine that's going to be recognised.
(just in case, I'm running Passenger 3.0.9, and Rails 3.2.11)

confused about apache server virtual host

So I configured a VirtualHost in the httpd-vhosts.conf directory, but whenever I navigate to the servername, it seems to always give me the page listed in httpd.conf.
I am new to apache web server and am not sure what else I need to do.
In my httpd-vhosts.conf I have
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName helloworld.com
DocumentRoot /Users/username/Desktop/RailsDemo/depot/public/
<Directory /Users/username/Desktop/RailsDemo/depot/public/>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In my httpd.conf, I have default settings, so I didn't change anything since install.
Also, I have matched helloworld.com to the correct ip address. Typing helloworld.com into the browser produces the wrong view...it produces the view indicated in httpd.conf.
If this helps, I am trying to do p. 238 of Pragmatic Agile Web Development with Ruby on Rails (4th Edition) -- Iteration K1: Deploying with Phusion Passenger and MySQL
Any help would be appreciated, thanks!
You seem to be running Mac OS X. In your httpd.conf, you will have the lines;
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Remove the comment, making it
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
Restart apache, and that should activate your named vhost.

Resources