Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been thinking a lot about this and can't find a way to do it, maybe it's not possible or maybe I just can't think of way. That's why I'm posting this here right...

Basically, I need to protected a folder in Apache from prying eyes, but on the other hand, I need some PHP scripts to access the contents of that folder.

Is this achievable?

P.S: I don't know if this question belongs here or in StackOverflow... My guess is that it belongs in both, but I had to choose one site.

share|improve this question
up vote 1 down vote accepted

If you mean your PHP script must access this folder locally, but you want to protect it from serving to clients, it is very easy:

<Directory /whatever/you/want/protect>
    Order deny,allow
    Deny from all

If not, please specify the exact situation, what you want to solve.

share|improve this answer
This question was asked more than 1 year ago, I don't even remember it's context :/ But I believe it was something like giving a 403 when people tried to access but if they opened that needed to access /some/folder to read some data, it needed to work. – Ricardo Amaral Oct 12 '11 at 23:53
The deny directive solves this problem anyway. Sorry for necroposting :-) – Gabor Garami Oct 13 '11 at 17:13
So, just so I know, will your solution work to the problem I just described or not? Did you test it? I'm a little confused... – Ricardo Amaral Oct 14 '11 at 14:11
I know it works, i copied it from a working webserver. – Gabor Garami Oct 20 '11 at 13:09

If the PHP script runs as a user that is not a shared one (something other than www, for instance) then you can just use standard Unix file permissions.

It is a good idea to use different users for every application to keep a compromise in one from killing another. If you run each application in this way, only the user running the script needs to access any of the private bits.

share|improve this answer
Isn't there any other way? – Ricardo Amaral Jan 17 '10 at 13:42

Your Answer


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.