Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

7 Answers

up vote 2 down vote accepted

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:

PassengerDefaultUser www-data

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.

share|improve this answer
add comment

See if you can get it to create a new file (say in /tmp) and see what user/group it creates it with.

share|improve this answer
add comment

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.

share|improve this answer
    
no write permissions for the dir. didn't know i needed that. and yes, it exists outside of the doc tree. if i chmod the file to 666, all works...so im not sure either of those would be the problem –  Tony Jun 10 '09 at 3:21
add comment

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.

share|improve this answer
add comment

Can happen that the file has the immutable attr set.

share|improve this answer
add comment

run 'ps aux' in a terminal window to see what user your rails app is running as.

share|improve this answer
add comment

Try it manually : become that user ( sudo su - www-data ) and try to create the file in the shell.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.