I was previously using an Ubuntu 16.04 VPS, and I was reading guides on how to set up my web site and WordPress. I was using the /var/www/html directory to host everything on there. Then I decided to move to a Debian 8 server so I could use PHP 5 instead of PHP 7, and the guides there said you should use /var/www/html/example.domain/public_html. What are the advantages and disadvantages of these two ways of hosting? Are there other ways to host besides these two methods? How exactly do these methods work? How does your server connect or associate the domain name with the IP address, if you are using a direct IP address to connect to your server via http in your browser?

  • 1
    If you connect by direct IP in your browser, it doesn't match the name host. You'd need some kind of DNS configured so that you can visit your server by name, or at least some method of forcing the hostname into your request headers
    – Fox
    Commented Feb 2, 2018 at 13:03
  • I saw on the Linode guide that you can add your server's IP to the hosts file on your local computer. Like /etc/hosts or c:\windows\system32\drivers\etc\hosts. You might have to flush your DNS cache, but instead of going to your nameservers to resolve the domain, it automatically uses the association you included in your hosts file. Commented Feb 2, 2018 at 13:39
  • 1
    Read about VirtualHosts and everything should be clear
    – DevilaN
    Commented Feb 2, 2018 at 13:43
  • Yes, the hosts file works too, though it ends up being more work if your server ever changes its address for any reason. In either case, you're contacting the server by name, not by IP
    – Fox
    Commented Feb 2, 2018 at 13:46
  • I already read about virtual hosts but there are no analogies or basic concepts for someone who is not super tech savvy. What makes a host physical or virtual? I know that a virtual machine is like a little machine running on a physical machine that actually takes up physical space. A virtual machine simply uses the resources of that physical machine. An emulator is similar to a virtual machine but it relies on the operating system as a subsystem. Commented Feb 2, 2018 at 14:01

1 Answer 1


The first part of the question - /var/www/html vs /var/www/html/example.domain/public_html - are just two different conventions on where to store your web site content: the former makes sense when you have more sites, usually served as VirtualHosts, so the directory would contain several sites (e.g. /var/www/html/{pub,doc,dev,prod,project1,projectX,...}, which themselves can contain public_html); whereas the latter suggests you are serving one main site, however nothing prevents you from adding some VirtualHosts later to different locations (e.g. /var/www/whatever.domain/public_html).

From another point of view the second approach just tries to prevent you from adding your site content directly to /var/www/html, which would complicate things in case you'd want to add another site later. Adding the site under one more dir (public_html) suggests you can use the site's root (example.domain) to store some related but not public stuff (e.g. example.domain/{resources,backup,SQLite.db,whatever_you_want_at_hand}.

Concerning the second part - naming the dirs doesn't have anything to do with associating domain names with IP addresses, that's what DNS is for (which is usually handled by a domain registrar or hosting provider). In the simplest case, DNS will translate your domain name to your IP address (provided to you by an ISP or hosting provider, or just test it with, localhost resp. see how /etc/hosts works), on your server a webserver (Apache, Nginx, ...) will serve your site to any incomming requests. Once you grasped this, check the VirtualHosts.

  • Okay, so that makes sense util you get to this point. If I host a second web site for my friend, something like /var/www/html/friend-example.org/public_html, how do you share a domain using the same IP address of your server, but not have it redirect to your first web site? Commented Feb 3, 2018 at 5:59
  • Directing requests to concrete locations or virtual hosts is really another topic - if lost, post a new question & link it here (I can add it to the question as a followup then). Commented Feb 7, 2018 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .