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?

Understanding www and public_html: Your Website’s Home Base

What are www and public_html directories, and why do they matter? In web hosting, public_html and www directories are the heart of your website, holding all the files—HTML, CSS, images, and scripts—that make your site accessible online. Whether you’re using shared hosting or cPanel, understanding these directories helps you manage your website like a pro. This guide breaks down their roles and how they work together to keep your site live and organized.

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: Take Control of Your Website’s Files

The

public_html
directory is your website’s core, serving all public content, while
www
is usually just a shortcut to it. By focusing on
public_html
for uploads and organization, you can keep your site running smoothly and accessible. Start managing your files with confidence, knowing both directories work together to bring your website to life!

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

Use code at checkout:

Skills