2

Before story:
We had a vserver with a domain around year 2004-2007 with apache. My father was owner and I was learning little bit from his friend (he was doing that stuff). I learned how to use linux via putty. I think we used there a system which was called confixx. There we had a linux user account which was "web1" there in /home folder with a html folder in it and all web stuff was there.

These days I use nginx and if I read articles they write always about "/var/www/" and "www-data" user. I even found an article which writes about www/web1 www/web2. It makes sense for me because sometimes I even have permission problems. Example if I upload file via php script it cannot move file because it belongs to www-data ( even if web1 has www-data group). I needed to change php config to that username.

How I do my setup:
Most time a vserver comes with a crazy domain like vserver1234.yourniceserver.com. I create subdomain or normal domain and the root html is under

  • /home/web1/sites/nameofthedomain/html
  • /home/web1/sites/nameofthedomain/subdomain/name/html
  • /home/web2/html its a special single domain.

I use my vserver most time to test things around, for own written fileshare system and wordpress-blog.

So the question is:

  • Did I all these years wrong?
  • Should I move that to "/var/www" folder?
    • If yes, it possible to use to create web1 user or need these folders to be owner of root? Because every user like web1, web2 can use ftp.

Edit: I use debian.

MaZy
  • 21
  • 2
  • 3
    "Wrong" in this case is not the correct term. You could say that your config differs from various defaults or "best practices", but it's not _wrong_ wrong. If you have one webserver and can use one user/group, just go with the defaults (`/var/www` and `www-data`), I believe it's massively simpler than different users and directories (e.g. the permissions). But you do you. – Lenniey Mar 09 '20 at 15:56
  • `/var/www` is a convention (cf. Debian's [FHS](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)). You'll have permission problems, whether it is `/var/www` or `/home`. A simple solution is to set all directories `setgid` and use an appropriate `umask` (like `007`). – Piotr P. Karwasz Mar 09 '20 at 21:49

2 Answers2

2

If you follow FHS closely, then from that you can decipher that /srv/www/example.com is the most appropriate of all. Despite being the least popular.

Appropriate, maybe not practical, however.

If you're working with CentOS/RHEL or other Fedora-based systems and intend to keep SELinux enabled, then, simply to match up with existing file context locations /var/www/html/example.com is most practical.

So e.g. if you put a Wordpress instance at /var/www/html/example.com, then it will work correctly without having to disable SELinux, because the files will have correct labels.

On RHEL 8 system, semanage fcontext -l | grep wp- yields:

...
/var/www/html(/.*)?/wp-content(/.*)?               all files          system_u:object_r:httpd_sys_rw_content_t:s0 
...

So the standard SELinux has "expectation" of files placed in either /var/www/html (single site per server) or /var/www/html/example.com (multiple websites on server).

However, as a personal preference, I would still stick to /srv/www/example.com and add the correct labeling with, e.g. semanage fcontext -a ...

Danila Vershinin
  • 5,286
  • 5
  • 17
  • 21
0

Your config is not specifically "wrong" (as in "it will not work"), but is definitely less than ideal; you are placing web server files and data in what is essentially a user home directory.

Sort of like if in Windows you placed your website root under C:\Users\Someone\wwwroot instead of C:\inetpub\wwwroot (or any more appropriate place, such as a dedicated data disk).

There isn't any practical difference for a single small web site, but nobody would use such a setup in a real web server.

Massimo
  • 70,200
  • 57
  • 200
  • 323