Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the directory structure should be for multiple domains under a single user? (apache)

I have an account on some VPS(friend's apache server with cPanel) and there I have one public_html directory. We have in there about 5-6 websites:

/home/myusername/public_html/domain-1.name/index.php
/home/myusername/public_html/domain-2.name/index.php

but I don't like this way, I'd like to orginise it better and be able to separate and isolate some stuff for each website. So what if I create like that:

/home/myusername/websites/domain-1.name/public_html/index.php

/home/myusername/websites/domain-2.name/public_html/index.php and so on

Would it be a correct way of structurising web directories? And would apache work like that? Perhaps there are out there some other conventions or common workarounds?

Thanks

like image 282
Alex Reds Avatar asked Jan 22 '26 02:01

Alex Reds


2 Answers

This is perfectly fine. In fact I'd highly recommend against using the domain folder as the document root as typical web application will also contain data that is not publically accessable (e.g. configuration files, management scripts, version control files, etc.)

Personally I prefer the name htdocs and I keep my sites under /srv/http

For example:

/srv/http/user1/domain1/htdocs/
/srv/http/user1/domain2/htdocs/
/srv/http/user1/domain3/htdocs/
/srv/http/user2/domain4/htdocs/
/srv/http/user3/domain5/htdocs/

That way you can set the DocumentRoot to the htdocs directory and put other stuff that is not meant to be delivered by the web server in a different sub directory of the domain directory.

like image 184
bikeshedder Avatar answered Jan 23 '26 21:01

bikeshedder


Ok, I want just to conclude and to outline the way I went with.
Thanks to @bikeshedder for ideas!

So having a single account(none-root) /home/myusername/ under linux VPS server, I didn't want to abstract completely from existent directory structure, but at the same time I wanted to create proper environment to isolate and separate clients and their spaces.

Main goals were:
* The new directory structure should help to keep all files and folders in a nice and clear order.
* Easy to navigate and browse.
* Each developer or client would have access only to their space.

The structure:

/home/myusername/http/client-1/domain-1/public_html/index.php
/home/myusername/http/client-1/domain-1/resources/
/home/myusername/http/client-1/domain-1/configuration.php
/home/myusername/http/client-1/domain-2/public_html/index.php
/home/myusername/http/client-1/client's_resource_dir/  

/home/myusername/http/client-2/domain-3/public_html/index.php
/home/myusername/http/client-2/domain-3/subdomain/public_html/index.php

As result:
* We have isolated client's space and isolated domain space. That makes enough room for any type of web projects.
* Files and dirs are not mixed up with other projects, domains and clients anymore.
* For subdomain paths it can be
- as subdirectories /domain-3.name/subdomain/public_html/
- or additional subdomain directory /subdomain.domain-3.name/public_html/depending on requirements or size of subdomain website.
* Public_html is going to be a DocumentRoot for each website.

I did not go for srv/ and var/www dirs, cuz to me it sounds like server in the server and also I don't feel variable data var/ in current setup falls under web stuff.
Though it may make sense for our coming soon local web/file sharing server

But here now I have another question:
How would I specify new path to be a default one for cPanel? and only for my user?
Cuz now there is going to be multiple DocumentRoot directories in one user space.
Is that possible by Apache design?
I better create new question :) And then will edit my question with answer

Any suggestion welcome!

like image 34
Alex Reds Avatar answered Jan 23 '26 21:01

Alex Reds