Ruby on Rails Setup: Unable to access log file - ruby-on-rails

I'm setting up Ruby on Rails for the first time; on my server, I've created and loaded the default rails app. I can view the default page ("Welcome aboard! You are riding Rails"), but when I go to click on the link to "View Application Environment", it generates a 500 error.
(You can view it here.)
I'd like to know more about the error, but, the log file ("log/production.log") is empty. Looking at my Apache log I find:
Rails Error: Unable to access log file. Please ensure that
/var/www/rails/myapp/log/production.log exists and is chmod 0666. The
log level has been raised to WARN and the output directed to STDERR
until the problem is fixed.
So, I actually want to get my Ruby on Rails error logging working.
I know this problem has been posted a few times before, but I tried everything I could find, so here's what I have tried:
Created the "log/production.log" file, set the owner to www-data, set chmod 0666.
Set the owner of the "log" folder to www-data, set chmod 0666.
Double-checked my production environment settings such that config.log_level = :info is set.
Checked that Apache is using the www-data user ("etc/apache2/envvars"):
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
"etc/apache2/mods-available/passenger.conf" has a default user set for Passenger:
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
PassengerDefaultUser www-data
</IfModule>
The owner of "config.ru" and "configs/environment.rb" is www-data
My virtual host has been set accordingly:
DocumentRoot /var/www/rails/myapp/public
RackBaseURI /
RackEnv production
PassengerMaxPoolSize 4
Already read and attempted all the fixes suggested in these places:
Rails: Unable to access log file
Can't access log files in production
http://railsforum.com/viewtopic.php?id=36168
Why am I getting Permission denied error in deployment on files generated by capistrano?
http://bradhe.wordpress.com/2011/06/26/a-sneaky-rails-3-bug-in-logging/
(That's all I can remember trying right now...)
Some environment settings of mine:
Ubuntu 11.10 running on Amazon EC2
Apache 2.2.20
RVM 1.10.2
Ruby 1.9.3p0
Rails 3.1.3

This issue is resolved now, though the the cause of the problem itself isn't entirely clear.
I had some weird configuration issues with Apache & Passenger (a.k.a. ModRails). Two modules existed: one that appeared to come packaged with Apache(?) and one I obtained via passenger-install-apache2-module. When I pointed to the pre-installed one, I had this logging issue. When I pointed to the one deployed by passenger-install-apache2-module, I had a completely different issue where Passenger would crash with a segfault (see my post on ServerFault here.)
In the end, I completely wiped my server and performed a clean install of everything from the base Ubuntu AMI (running on Amazon EC2 made this easy enough.) Upon reinstalling, I ran passenger-install-apache2-module and configured Apache to load the module deployed by it. This time, the module didn't crash, but the log error appeared. I set chmod 755 on the root of my Rails application, made sure the production.log existed and that it had at least chmod 0666 privileges. And voila, problem gone.
TL;DR Did a fresh install, made sure I was using the latest Passenger module, and my file permissions were set properly.

Related

RailsEnv misspelled or defined by a module not included in the server configuration

I am following this link http://blog.redpanthers.co/2015/10/how-to-deploy-a-rails-app-with-passenger-and-apache-in-ubuntu-14-04/ in order to install ruby on rails with rvm and passenger. I was fine until I got to configuring my demo.conf file using this command sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/demo.conf. When I tried to change RailsEnv production to RailsEnv dev or RailsEnv development it says that perhaps RailsEnv is misspelled or defined by a module not included in the server configuration. I tried to change this setting because the link says its necessary to be in the development environment in order to see the welcome aboard page. I dont know how to give you a copy of my error log file as I am running ubuntu 14.04 server on vmware and I can't copy out of that. I have pastebinit installed, so if anyone knows how I can copy code from the error.log file to show you why I am getting this error, please advise. Also I would like to know how to configure the acccess control as I am using apache 2.4 and the link im following isnt very clear. I would appreciate any help on this as I am doing it for a college project and I am hitting many walls with completing this installation. please bare in mind I am new to linux.
RailsEnv development AND restarting apache should do the trick:
service apache2 restart

Apache2 Won't Reload: Looking for a File I Intentionally Deleted

Okay, so I'm following a guide to get set up with a Rails production server, and it says the following in the Apache2 setup:
We have to create a virtual host by creating a file in the "/etc/apache2/sites-available" directory (we will name it "site" - the file won't have any extension but it will be a text file).
$ sudo nano /etc/apache2/sites-available/site (this will create the file named "site" - can be any name - AND open it for editing)
Copy and paste this into that file (compare also with what the notes after installing mod_rails tells you):
VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /home/user/public_html/site/public
/VirtualHost>
When I was first testing the waters with Apache I did as it said, making a fake scaffolded Rails app called "site". Now I want to use my real site, which we'll call "realthing." So I did
# sudo mv /etc/apache2/sites-available/site /etc/apache2/sites-available/realthing
And put my new settings into the renamed file. So far so good.
Then I went to restart Apache. Problems begin.
# sudo a2ensite realthing
Enabling site realthing.
To activate the new configuration, you need to run:
service apache2 reload
Okay, I can do that.
# sudo service apache2 reload
apache2: Syntax error on line 230 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/sites-enabled/site: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
Fail indeed. Nothing I can seem to do can get this thing to restart without flipping out about the missing "site" file. I check line 230 of /etch/apache2/apache2.conf for any specific references. Nope:
Include sites-enabled/
It's a generic reference to the folder containing "site". But no mention of "site".
So what's up? How do I get Apache to forget about the fake site "site" and move on to the real thing "realthing"? It's driving me insane that even a superuser reload is failing because Apache can't find a file that as far as I can tell it has no reason to expect to find.
Even a hard
sudo service apache2 stop
and
sudo service apache2 start
doesn't work. Again with the
* Starting web server apache2
apache2: Syntax error on line 230 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/sites-enabled/site: No such file or directory
Action 'start' failed.
This is driving me bonkers. Any ideas?
The Apache error log may have more information.
You probably still have a symlink from sites-enabled/site to the now missing sites-available/site

Rails/Passenger/Nginx user permission errors

My Rails app is having trouble writing into it's public/ directory. I've setup nginx with user root;, the capistrano recipe I'm using also is using root when connecting via ssh.
To fix this I made capistrano run chmod o+w -R #{current_path}/ but I don't think this is a good solution. What am I missing?
According to Phusion Passenger's documentation:
Under no circumstances will applications be run as root. If
environment.rb/config.ru is owned as root or by an unknown user, then
the Rails/Rack application will run as the user specified by
passenger_default_user and passenger_default_group.
http://modrails.com/documentation/Users%20guide%20Nginx.html#user_switching

Ruby error on non-ruby site

A friends of mine have a shared hosting with many sites hosted. There is ruby on rails, php, xslt/xml sites using mysql or postgress. Today one of the xslt sites displays this error:
Passenger error #2
An error occurred while trying to access '..../config/environment.rb': Cannot stat '..../config/environment.rb': Permission denied (13)
Apache doesn't have read permissions to that file. Please fix the relevant file permissions.
This is, as I Know, a ruby error (*.rb), but there is no ruby app here! And no any config/ catalogue.
The error log says:
(13)Permission denied: /home/..../.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
The .htaccess file in the htdocs directory is present and have 777 permission for now.
I haven't any idea what does it mean.
I experienced the same problem, Passenger error #2, suddenly and without correlation to any configuration change on my part. I did not add Ruby. I contacted host monster tech support, their level 2 support was baffled.
Confirming that Jaap Haagmans' solution; overriding PassengerEnabled with no from the .htaccess located in public_html works. Thank you kindly Mr.Haagmans.
I think the configuration of either your apache or nginx state that passenger is enabled. Check for a "passenger_enabled on" on nginx or "PassengerEnabled on" on apache in your webserver configuration file. Then disable it on top level or in the virtual host that runs a php website.
You could instead try to put "PassengerEnabled on" in a .htaccess file in the public_html folder (or equivalent, e.g. httpdocs). Also, make sure the .htaccess file is readable (e.g. 644 permissions in Linux), as that's what the error in your error log is saying.
Looks like there are some leaks in the web host's configuration. Passenger (which is like a mod_rails apache extension) is looking to load a particular Rails app's configuration, presumably not yours. If you're doing something important (like an e-commerce site) I'd run far away from the hosting company. Otherwise you'll have to get this resolved through them.

Can't access log files in production

I was trying to run my application and check for some output on the production.log. However Ruby on Rails throws this error.
Apache log
Rails Error: Unable to access log file. Please ensure that /var/www/somefolder/someapp/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
I have performed the necessary chmod 666 production.log to make it work but I realized that the file is under root access.
So my file permissions are
-rw-rw-rw- 1 root root 20845 2010-03-18 01:18 production.log
I'm not sure how to allow Ruby on Rails to access this file. I'm fairly new to managing a Linux production environment so I request you to excuse my ignorance.
I think you need to change the user and group of production.log to whatever user and group Rails (i.e. Passenger or Mongrel or whatever you are using) runs under.
Okay I just figured it out.
First need to update Apache.conf passenger configurations:
PassengerDefaultUser username
The assign ownership using chown:
chown -R username:username <folder>
I don't know if this is the right way but it worked for me.

Resources