What is www and public_html directory in my folder? ⋆ ALexHost SRL

Test your skills on our all Hosting services and get 15% off!

Use code at checkout:

Skills
09.10.2024

What is www and public_html directory in my folder?

In web hosting environments, especially those using shared hosting or cPanel, you will often encounter directories named www and public_html within your hosting account. These directories are essential for managing and serving the content of your website. Here’s an explanation of what these directories are, their purposes, and how they relate to each other.

public_html Directory

  • Definition: The public_html directory is the root directory for your website on a web server. It is the default folder where web content (HTML files, images, CSS, JavaScript, etc.) is stored. Any files placed inside the public_html directory can be accessed via the internet using your domain name.
  • Purpose:
    • It serves as the document root for your primary domain. For example, if your domain is example.com, any file or folder inside public_html can be accessed using https://example.com.
    • This is where you should upload your website files if you want them to be accessible to the public. For example:
      • An index.html file placed in public_html will be displayed when users visit https://example.com.
      • A file called about.html placed in public_html can be accessed using https://example.com/about.html.
  • Common Files and Folders Inside public_html:
    • index.html / index.php: The main file that loads when someone visits your domain.
    • css/: A folder that might contain CSS files for styling.
    • js/: A folder that might contain JavaScript files.
    • images/: A folder for storing images used on the website.

www Directory

  • Definition: The www directory is typically a symbolic link or shortcut that points to the public_html directory. It exists for compatibility and historical reasons.
  • Purpose:
    • The www folder provides an alternative path to the public_html directory. It is essentially another way to access the same content stored in public_html.
    • For most practical purposes, placing files in the www folder is the same as placing them in public_html, as they reference the same directory.
  • Why Does It Exist?:
    • The www directory is a legacy feature from older web hosting environments and is often maintained to ensure compatibility with scripts and websites that expect to find a www directory.
    • Some users are more familiar with using www as the root directory of their website, so hosting providers often include it for convenience.

How www and public_html Work Together

  • Symbolic Link Relationship:
    • In many hosting setups, www is a symbolic link (or symlink) to public_html. This means that both directories point to the same location on the server. Any files or changes made in one directory will be reflected in the other.
    • For example:
      • If you place a file contact.html inside public_html, it will also appear inside www because www is a pointer to public_html.
  • Accessing Files Using Both Paths:
    • From a user’s perspective, there is no difference between using www and public_html. Both are mapped to your domain, so accessing a file from either directory will work the same way.
    • If you upload a file to www, you are essentially uploading it to public_html and vice versa.

Example Scenario

Suppose you have a hosting account with the domain example.com and you see the following directories:

  • public_html/index.html
  • www/index.html

If you upload or modify index.html in either public_html or www, it will be accessible through your browser at https://example.com/.

Differences in Some Hosting Environments

  • cPanel-based Hosting: Most shared hosting environments using cPanel will use public_html as the default document root for the primary domain, with www as a symbolic link to it.
  • Custom Server Setups: In custom server setups, www may or may not exist, depending on how the server is configured. However, public_html (or a similar directory) is always necessary as a document root to serve web pages.
  • Subdomains and Add-on Domains: For subdomains or add-on domains, separate directories inside public_html or alongside it may be created. For example:
    • public_html/subdomain/ for subdomain.example.com.
    • public_html/addon-domain/ for addon-domain.com.

Conclusion

The public_html directory is the primary directory for storing website files that you want to make accessible via the internet. The www directory often exists as a symbolic link to public_html and serves the same content. Understanding the relationship between these directories is important for managing your website’s files, ensuring that they are properly organized and accessible.

In most cases, you can simply focus on using the public_html directory for uploading and managing your website’s content. However, if you see both www and public_html on your server, remember that they likely point to the same location and will behave the same way when serving your website’s content.

Test your skills on our all Hosting services and get 15% off!

Use code at checkout:

Skills