passenger
passenger copied to clipboard
Rails app : ``cannot load such file config/environment`` instead of ``config/environment.rb`` (in apache logs)
Question 1: What is the problem?
- What is the expected behavior? We expect to see the home page of our Rails application.
- What is the actual behavior? We get "We're sorry, but something went wrong." .
- How can we reproduce it? Just browse http://back.alliancecybertech.eu:3003/
- In Apache logs we find :
cannot load such file -- /var/www/OUR_APP_NAME/config/environment (LoadError)
but the only corresponding file in this folder isenvironment.rb
and notenvironment
... this seems very wird that the path called by the server is not pointing on the real file name. What do you think ? - You find logs and configuration files at the end oh the post .
Question 2: Passenger version and integration mode:
- Phusion Passenger(R) 6.0.15
Question 3: OS or Linux distro, platform (including version):
- Ubuntu 20.04 + Apache/2.4.41
Question 4: Passenger installation method:
[ ] RubyGems + Gemfile [X] RubyGems, no Gemfile [X] Phusion APT repo [ ] Phusion YUM repo [ ] OS X Homebrew [ ] source tarball [ ] Other, please specify:
Question 5: Your app's programming language (including any version managers) and framework (including versions):
- Ruby 3.1.2, RVM 1.29.12, Rails 7.0.4; Node.js v18.6.0
Question 6: Are you using a PaaS and/or containerization? If so which one?
- None (as far as I know).
Question 7: Anything else about your setup that we should know? We installed all the following dependences as 'sudoer' : apache, gem passenger, Phusion Passenger, RVM, Ruby, Rails. The port we use is 3003 for our virtual host, and is open.
The virtual host configuration file :
<VirtualHost *:3003>
# 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 webmaster@localhost
DocumentRoot /var/www/raw-rails-for-tests/public
ServerName back.alliancecybertech.eu
PassengerRuby /usr/local/rvm/gems/ruby-3.1.2/wrappers/ruby
# Relax Apache security settings
<Directory /var/www/raw-rails-for-tests/public>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache > 2.4:
#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
LogLevel info passenger: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>
The error.log of apache (right after a apache restart + try to display our home page):
[ N 2022-11-30 14:32:41.7333 187859/T9 age/Cor/CoreMain.cpp:670 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ N 2022-11-30 14:32:41.7334 187859/T1 age/Cor/CoreMain.cpp:1245 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ N 2022-11-30 14:32:41.7337 187859/T9 Ser/Server.h:901 ]: [ServerThr.1] Freed 0 spare client objects
[ N 2022-11-30 14:32:41.7337 187859/T9 Ser/Server.h:558 ]: [ServerThr.1] Shutdown finished
[ N 2022-11-30 14:32:41.7338 187859/Tc Ser/Server.h:901 ]: [ServerThr.3] Freed 0 spare client objects
[ N 2022-11-30 14:32:41.7338 187859/Te Ser/Server.h:901 ]: [ServerThr.4] Freed 0 spare client objects
[ N 2022-11-30 14:32:41.7338 187859/Te Ser/Server.h:558 ]: [ServerThr.4] Shutdown finished
[ N 2022-11-30 14:32:41.7338 187859/Tc Ser/Server.h:558 ]: [ServerThr.3] Shutdown finished
[ N 2022-11-30 14:32:41.7338 187859/Tg Ser/Server.h:901 ]: [ApiServer] Freed 0 spare client objects
[ N 2022-11-30 14:32:41.7338 187859/Ta Ser/Server.h:901 ]: [ServerThr.2] Freed 0 spare client objects
[ N 2022-11-30 14:32:41.7339 187859/Tg Ser/Server.h:558 ]: [ApiServer] Shutdown finished
[ N 2022-11-30 14:32:41.7339 187859/Ta Ser/Server.h:558 ]: [ServerThr.2] Shutdown finished
[ N 2022-11-30 14:32:41.7378 187859/T9 age/Cor/CoreMain.cpp:670 ]: Signal received. Gracefully shutting down... (send signal 1 more time(s) to force shutdown)
[ N 2022-11-30 14:32:41.8603 187859/T1 age/Cor/CoreMain.cpp:1325 ]: Passenger core shutdown finished
[ N 2022-11-30 14:32:41.9597 189096/T1 age/Wat/WatchdogMain.cpp:1377 ]: Starting Passenger watchdog...
[ N 2022-11-30 14:32:41.9886 189108/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2022-11-30 14:32:41.9888 189108/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2022-11-30 14:32:42.0040 189108/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 189108
[ N 2022-11-30 14:32:42.0198 189108/T8 age/Cor/CoreMain.cpp:670 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ N 2022-11-30 14:32:42.0198 189108/T1 age/Cor/CoreMain.cpp:1245 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ N 2022-11-30 14:32:42.0199 189108/Ta Ser/Server.h:901 ]: [ServerThr.2] Freed 0 spare client objects
[ N 2022-11-30 14:32:42.0199 189108/Ta Ser/Server.h:558 ]: [ServerThr.2] Shutdown finished
[ N 2022-11-30 14:32:42.0199 189108/Td Ser/Server.h:901 ]: [ServerThr.3] Freed 0 spare client objects
[ N 2022-11-30 14:32:42.0199 189108/T8 Ser/Server.h:901 ]: [ServerThr.1] Freed 0 spare client objects
[ N 2022-11-30 14:32:42.0199 189108/Td Ser/Server.h:558 ]: [ServerThr.3] Shutdown finished
[ N 2022-11-30 14:32:42.0199 189108/T8 Ser/Server.h:558 ]: [ServerThr.1] Shutdown finished
[ N 2022-11-30 14:32:42.0200 189108/Te Ser/Server.h:901 ]: [ServerThr.4] Freed 0 spare client objects
[ N 2022-11-30 14:32:42.0200 189108/Te Ser/Server.h:558 ]: [ServerThr.4] Shutdown finished
[ N 2022-11-30 14:32:42.0200 189108/Tg Ser/Server.h:901 ]: [ApiServer] Freed 0 spare client objects
[ N 2022-11-30 14:32:42.0200 189108/Tg Ser/Server.h:558 ]: [ApiServer] Shutdown finished
[ N 2022-11-30 14:32:42.0612 189133/T1 age/Wat/WatchdogMain.cpp:1377 ]: Starting Passenger watchdog...
[ N 2022-11-30 14:32:42.0895 189137/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2022-11-30 14:32:42.0897 189137/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2022-11-30 14:32:42.0971 189108/T1 age/Cor/TelemetryCollector.h:531 ]: Message from Phusion: End time can not be before or equal to begin time
[ N 2022-11-30 14:32:42.1031 189137/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 189137
[Wed Nov 30 14:32:42.105343 2022] [mpm_event:notice] [pid 189131:tid 139940353662016] AH00489: Apache/2.4.41 (Ubuntu) Phusion_Passenger/6.0.15 configured -- resuming normal operations
[Wed Nov 30 14:32:42.105487 2022] [core:notice] [pid 189131:tid 139940353662016] AH00094: Command line: '/usr/sbin/apache2'
[ N 2022-11-30 14:32:42.1486 189108/T1 age/Cor/CoreMain.cpp:1325 ]: Passenger core shutdown finished
[ N 2022-11-30 14:32:44.1990 189137/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
App 189221 output: Error: The application encountered the following error: cannot load such file -- /var/www/raw-rails-for-tests/config/environment (LoadError)
App 189221 output: config.ru:3:in `require_relative'
App 189221 output: config.ru:3:in `block in <main>'
App 189221 output: /var/www/raw-rails-for-tests/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:125:in `instance_eval'
App 189221 output: /var/www/raw-rails-for-tests/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:125:in `initialize'
App 189221 output: config.ru:1:in `new'
App 189221 output: config.ru:1:in `<main>'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/helper-scripts/rack-preloader.rb:101:in `eval'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/helper-scripts/rack-preloader.rb:101:in `preload_app'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:397:in `run_block_and_record_step_progress'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/helper-scripts/rack-preloader.rb:188:in `<module:App>'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
App 189221 output: /usr/local/rvm/gems/ruby-3.1.2/gems/passenger-6.0.15/src/helper-scripts/rack-preloader.rb:29:in `<main>'
[ E 2022-11-30 14:32:46.9594 189137/Tj age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/raw-rails-for-tests: The application encountered the following error: cannot load such file -- /var/www/raw-rails-for-tests/config/environment (LoadError)
Error ID: 6f44d802
Error details saved to: /tmp/passenger-error-0VWqnQ.html
[ E 2022-11-30 14:32:46.9637 189137/T9 age/Cor/Con/CheckoutSession.cpp:281 ]: [Client 1-1] Cannot checkout session because a spawning error occurred. The identifier of the error is 6f44d802. Please see earlier logs for details about the error.
This problem can be related to missing permissions in some directories in the /var/www/raw-rails-for-tests/config/environment
path.
In my case the Nginx was run under the nobody
user and the /rails/config
directory doesn't have execution
permissions for group
and other
users:
root@98b95d1fe591:/rails# namei -lm /rails/config/environment.rb
f: /rails/config/environment.rb
drwxr-xr-x root root /
drwxr-xr-x root root rails
drwxr--r-- root root config
-rw-r--r-- root root environment.rb
Compare with this output after execution of chmod ugo+x /rails/config
command:
root@98b95d1fe591:/rails# namei -lm /rails/config/environment.rb
f: /rails/config/environment.rb
drwxr-xr-x root root /
drwxr-xr-x root root rails
drwxr-xr-x root root config
-rw-r--r-- root root environment.rb