views:

36

answers:

2

Seems it is a question about .htaccess, not sure what should I use.

How can I make files inside /data/ folder available to read and write only for scripts?

Users should not have access to them from browser window.

+1  A: 

You can change the ownership of the directory to the www or apache user, depending on what user your web-server is running as.

Then make sure that the permissions of the directory are set to 644 so that only the owner can write. If you want nobody else to be able to read, just make it 600.

jeroen
That wouldn't make them unavailable to users through HTTP as specified. That would affect other local users on the server.
Alex JL
600 - nobody can access, even scripts?
Happy
@Alex JL, that´s true, they should definitely be outside of the web server's document root, but when I read `/data/` I kind of assumed that already.
jeroen
@Happy, if the user that runs the web-server owns the directory, it can still read and write with permissions 600.
jeroen
True, but it's not clear whether `/` refers to the file system root or web server root. I think he means the web server root. Otherwise, they'd already be unavailable.
Alex JL
@Alex JL, yes, reading the question again, my assumption doesn´t seem quite right...
jeroen
+7  A: 

Simplest way to block access to non-scripts: move it outside the web server's document root. If your PHP files are served from /var/www/htdocs, put your data files in /var/www/data.

If that's not possible, the .htaccess solution looks like:

# don't let anyone access these files directly
Order allow,deny
Deny from all
Adam Backstrom
Where should I put this file?
Happy
You can put it right in your `data` directory. `.htaccess` files affect child directories, so this change will block access to whatever directory it's placed in, plus all children. (Until it's overridden by something else.)
Adam Backstrom