1

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!

7 Answers 7

2

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.

1

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

0

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.

1
  • 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, 2009 at 3:21
0

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.

0

Can happen that the file has the immutable attr set.

0

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .