EastsideDev
EastsideDev

Reputation: 6639

Rails application going into production mode when it's supposed to be in staging mode

Ubuntu 18.04    
Rails 5.2.3
Apache > 2.4
Phusion Passenger
Webbpacker

My application is running fine on my development machine, but I am trying to buikd abd deploy to the staging server.

The application is deployed to

/home/myappstaging

When I deploy it, I login with the username myappstaging, and from the command shell, if I do:

printenv

I get:

RAILS_MASTER_KEY=xxxxxxxxxxxxxxxxxxxxx
USER=myappstaging
RAILS_ENV=staging
RAILS_USER=myappstaging
RAILS_DB_NAME=myappstaging
RAILS_DB_PWD=xxxxxxxxxxxx   
RAILS_DB_USER=myappstaging

In my config/database.yml file, I have:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  host: localhost
  database: <%= ENV["RAILS_DB_NAME"]%>
  username: <%= ENV["RAILS_DB_USER"]%>
  password: <%= ENV["RAILS_DB_PWD"] %>

staging:
  <<: *default

When I upload the code to the staging server, I do:

RAILS_ENV=staging bundle install
RAILS_ENV=staging bundle exec rails webpacker:install
RAILS_ENV=staging rake db:migrate
RAILS_ENV=staging rake db:seed
RAILS_ENV=staging bundle exec rake assets:precompile

However, when I try to access the application from my local browser, I get the "Something went wrong" screen.

Looking into the log directory, I see two log files:

staging.log
production.log

In staging.log, I see records of the DB migration, and seeding of the DB.

In production.log, there's the error that produced the "something went wrong" screen:

Started GET "/users/sign_in" for xx.xxx.xxx.xxx at 2019-09-11 14:02:11 +0000
Processing by User::SessionsController#new as HTML
Completed 500 Internal Server Error in 1ms

Mysql2::Error::ConnectionError (Access denied for user 'myappstaging'@'localhost' (using password: NO)):

Clearly, it thinks it's running in production mode, and this is why it cannot connect to the DB. Any idea why this is happening?

PS: If I start the rails server from the command line, I get no error messages.

Apache Config file:

<VirtualHost *:80>
   ServerName myserver.com

   DocumentRoot /home/myappstaging/public

   PassengerRuby /path-to-ruby

   <Directory /home/myappstaging/public>
     Allow from all
     Options -MultiViews
     Require all granted
   </Directory>
</VirtualHost>

Upvotes: 0

Views: 260

Answers (1)

Violet Shreve
Violet Shreve

Reputation: 1138

You need to tell passenger which rails environment to use. It's defaulting to production.

<VirtualHost *:80>
   ServerName myserver.com

   DocumentRoot /home/myappstaging/public

   PassengerRuby /path-to-ruby

   <Directory /home/myappstaging/public>
     Allow from all
     Options -MultiViews
     Require all granted
     RailsEnv staging 
   </Directory>
</VirtualHost>

Upvotes: 1

Related Questions