Working with folders and folder permissions with Ruby on Rails

I am running Ruby on Rails 3.0.9 in production mode on a remote VPS computer with Ubuntu 10.04 LTS (in development mode I use RoR on MAC OS Snow Leopard), and I would like to know how to manage the following scenario.

I use Apache2 and Phusion Passenger, and I installed Virtual Host somehow:

<VirtualHost *:80> ServerName project_name.com DocumentRoot /srv/www/project_name.com/public <Directory /srv/www/project_name.com/public> AllowOverride all Options -MultiViews </Directory> </VirtualHost> 

More, I use the Paperclip gem and, like many people on the Internet using it in production mode, I get the following error when processing (creating) files:

 Errno::EACCES (Permission denied - /srv/www/project_name.com/public/images/001): ... 

I heard that the solution to avoid such errors is to correctly set the rights to the folder (manually!) - I don’t know if this installation process can be automated ... BTW: is this possible?), But I think that There is a better way to solve this. If so, what can I do?

+6
source share
2 answers

@M. Cypher is close, although the biggest problem I see is that you allow users to download arbitrary files and then mark them with all executable files. This is a disaster in search of a place.

 find /srv/www/project_name.com/public -type d -exec chmod 755 {}\; find /srv/www/project_name.com/public -type f -exec chmod 644 {}\; 

This will install the executable in directories (required), but not in the files.

+2
source

Why automate it, you just need a simple command on the server.

 sudo chmod -R 777 /srv/www/project_name.com/public 

Edit: I have all of my clip images in a shared directory, for example. /srv/www/project/shared/... Thus, they are not affected when I deploy a new version with Capistrano, and I only need to set permissions for the folder once (using the specified command or the like). Therefore, I believe that automation is not needed, since you need to run the command exactly once, and not after each deployment.

Btw, chmod -R 777 may not be the best choice, as it indiscriminately installs every file in each subfolder to be accessible to everyone. It works, but I'm sure someone with a lot of Linux skills can indicate why a less extreme version will be smarter.

+1
source

Source: https://habr.com/ru/post/894096/


All Articles