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 am using Centos 5.5

Let's say I have 2 directories:



If a file is created in /var/www/read is it possible to have it "redirected" so that it's actually created in /var/www/write and NOT in /var/www/read?

e.g. Trying to create /var/www/read/directory/directory/newfile.txt actually ends up creating /var/www/write/directory/directory/newfile.txt


I want any Apache writes to be in a different directory then where it reads from. I can't do this directly in the php code as it's encrypted.

share|improve this question
It's not possible as you describe it. If you provide more details as to your goal, we may be able to provide an alternate solution. – Warner Jul 2 '10 at 18:42

Generally, no. Apache just runs your php (or whatever) code. The application can write to any directory the running user has write permission for (if you're using mod_php, then this user is the same user the webserver runs as).

share|improve this answer
How about at the filesystem level? – Travis Jul 2 '10 at 17:55

Well, you could have a cron job periodically move the new files from the read directory to the write directory.

Or you could build a chroot environment for apache where everything was the same except that you mounted the write directory over the read directory. You could just bind mount the write directory over the read directory right now but if you have to shuffle many things about just go all the way to full chroot instead of later.

UPDATE: Using chroot on apache is visible only by apache while doing a bind mount only of write-over-read is visible by the the entire system.

share|improve this answer

It sounds like you want /var/www/read to be read-only. The technique is similar to that used for Linux LiveCDs. Use unionfs or aufs to divert writes at the filesystem level. Scientific Linux, a sibling of CentOS, comes with a kernel-module-aufs package.

share|improve this answer

Your Answer


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