I have a rails app on an Ubuntu server. In my Apache config I have set the user and group to www-data. I want my rails app to write to a file. I have set the file permissions as follows:
-rw-rw-r-- 1 www-data www-data 0 Jun 5 22:35 notify_list.txt
Seems like rails should be able to write because the permissions are correct. But I keep getting permission denied. What are possible causes of this?
Thanks!
Are you running your Rails application under Apache via mod_rails/passenger?
You may need to set the user that passenger runs the Rails application with "PassengerDefaultUser". Since you mention www-data, I'm assuming an ubuntu or debian server, so this would probably be a separate vhost file in /etc/apache2/sites-available. Add the line:
To the correct vhost file. If you don't know which file, run "
sudo apache2 -S
" to show the available vhosts in the configuration and pick the file that matches the hostname you access the Rails app.See if you can get it to create a new file (say in /tmp) and see what user/group it creates it with.
First idea: Do you have write permissions for the directory?
Also, depending on the apache config, you might not have access to files outside the document tree, so if you app lives in /var/www/htdocs, you won't have access to files outside this directory.
Sorry for asking the obvious, but... are you running rails in Apache? Because if you are running rails in Mongrel or similar you need to make Mongrel run as www-data.
Can happen that the file has the immutable attr set.
run 'ps aux' in a terminal window to see what user your rails app is running as.
Try it manually : become that user (
sudo su - www-data
) and try to create the file in the shell.