If vhosts are enabled, where should I place my website files?

  1. /home/aunser/www
  2. /var/www/site1, /var/www/site2
  3. /usr/local/website/site1, /usr/local/website/site2

the systems is CentOS 6.x/RHEL 6.x,SELinux enabled.

  • 1
    While the answers are correct that it doesn't really matter where you put them, I would offer that /var/www/site1, /var/www/site2 is a widely used convention that will be familiar to many folks, so standardizing there can be beneficial. – Tim Kennedy Jun 16 '14 at 22:47
  • 1
    @TimKennedy, especially if you have something like SELinux on your system, which can automatically apply the appropriate file contexts and/or access restrictions to your server's files. :D – ILMostro_7 Jun 17 '14 at 7:33

For apache it doesn't matter, you simply define a DocumentRoot pointing to the directory where the files are.

From a practical perspective it might be good to follow the conventions of the distribution you're using, as things like SELinux and possibly AppArmor may have default policies that require modification when Apache is pointed to non-default locations.

| improve this answer | |

If you mean where should you place the files for apache to be able to access them, then...

It's entirely up to you where you place your files. You configure your vhost to use whatever path you choose to use using the DocumentRoot directive.

As well as the normal Discretionary Access Control settings (users and groups), depending on your distro, you may need to reconfigure Mandatory Access Control (SELinux or AppArmor etc) to allow apache read or read/write access to the documents.

| improve this answer | |

Apache itself doesn't care — it uses whatever you write in your vhost configuration. However the administrators of the machine care: you should follow conventions. If you don't follow the usual convention, you may have a hard time with package managers.

Data under /home is supposed to belong to a particular user. This is not normally appropriate for the content of a website.

The directory /usr is meant for installed programs. It doesn't change except when you install or upgrade programs. Don't put a web root there.

The two normal locations for web server roots are:

  • Under /srv, which is meant for this kind of stuff;
  • or under /var, which is meant for data that varies during the normal life of the system — usually in /var/www/VHOST_NAME.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.