Site5 - Built For Designers & Developers MENU
Home  ›  Domain Names  ›  Domains: How to Host a Domain Outside of the public_html Directory

Domains: How to Host a Domain Outside of the public_html Directory

2 Comments

In this article, we will show you how to host your domain outside of the public_html directory.

There are two methods you can use:

1. You can change the website path for the addon/subdomain to point to a directory outside of the public_html folder. With this option, it can take an unknown amount of time to become live because an Apache restart is required for the changes to be noticed. Because of this, we recommend that you use the following methods instead.

2. You can use a symbolic link to point to link to a folder outside of the public_html directory. Because you still have a link inside of your public_html folder, this change will be almost instant (assuming domain propagation is already completed).

Here are the steps for each method…

Symbolic Link

This article assumes that you already have your domain added as an addon domain, or a sub-domain.

If you already have content hosted on your domain, either make a copy of the folder, or move the folder to where you would like it to reside on the account.

1) Open a SSH client and connect to your account.

2) If you have not already moved/created the folder where you want your actual files to be hosted, create it now. For this example, we will be using “example.com” and we will keep the files in ~/sites/example_com, you can use whatever you wish. For this example, we are going to assume that you are uploading a new site, because of this, we need to create the folder structure. We can do this by running the following two commands.

mkdir ~/sites/
mkdir ~/sites/example_com

3) We want to check and make sure nothing is in the default directory that was created when we added the domain. We can do this by entering the following command.

ls ~/public_html/example.com

Make sure you replace example.com with your domain. If you only see “./” and “../” then the directory is empty. If you see other files, make sure you make a backup and then move them to the folder we created above.

3) Now we need to create the link itself. To do this, run the following command:

ln -s ~/sites/example_com ~/public_html/example.com

Remember to replace the /sites/example_com with the location your files are being hosted. You will also want to replace example.com with your domain.
These steps assume that you have not changed the default website path for your domain. By default, when you add a new domain to your account, it creates a folder in your public_html directory that matches the domain name. For example, if you add example.org to your account as an addon domain, it will create a folder in your public_html directory called “example.org”. If you changed your website path, you will need to change the folder links above to reflect your changes.

Website Path

Next we will show you how to use the website path method. Use the following two links to see how to access and change the website path using your control panel.

Addon/Sub Domains

You will notice that the default path says “/public_html/domain”, we can change this to whatever folder we want. For example, we can replace it with “/sites/domain” to host it from outside the public_html directory.

Please note, you should have the folder created before you attempt this change. You can create it using the first 2 steps of the previous sections, FTP, or you can use the file manager built into the control panel.

 

Still have a question? Or need help?
See an error in this article or want to suggest a missing topic? Please leave us a comment below! If you need technical support with your account, please email us, chat live with a representative, or call us!

2 Comments

  • The above is actually out of date and inaccurate.

    In the latest iteration of the Addon Domain interface you can point your addon domain directly to the desired directory. If you are creating a new add on domain simply substitute the desired directory (e.g. sites) for public_html in the Addon Domain manager interface.

    Similar to above, if you already have content hosted on your domain:

    1) Open a SSH client and connect to your account.

    2) If you have not already moved the folder where you want your actual files to be hosted, create it now. For this example, we will be using “example.com” and we will keep the files in ~/sites/example_com, you can use whatever you wish. We can do this by running the following two commands.

    mkdir ~/sites/
    mv ~/public_html/example.com ~/stes/

    3) Open Site5’s Addon Domain manager. Edit the entry for your application and change ‘public_html’ to ‘sites’ and save.

    4) Open the FTP manager. Delete the entry for example.com. Create a new entry for example.com remembering to select /home/username instead of public_html and enter sites/example.com as the FTP directory.

    The above all assumes that you have not used the Web App manager to create/manage the domain. If that is the case then the following steps ‘MAY’ work. Use at your own risk. You must know about how your app is configured and how to manage your DB to do the following.

    Beware, deleting an application in the Web App manager does delete the associated database breaking the application. To delete a web app safely you should first save the DB so that it can restore it.

    The Web App manager WILL allow you to do fresh installs in Addon domains that have already been set up in the new directory structure, but the ability to reassign an app to a new directory outside public_html is broken!

    The work around for all of this is to:

    1. Rename of the site directory: e.g. mv example.com example.com.bak
    2. Save a backup of the DB from the phpMyAdmin interface
    3. Delete the application through the Web App interface
    4. Delete and recreate the addon domain in the new directory through the Addon Domain manager
    4. Install the app again fresh to the new directory in the Web App manager (as pointed to in Addon Domain manager)
    5. Rename the site fresh directory to example.com.new
    6. Rename the example.com.bak to example.com e.g:
    mv ~/public_html/example.com.bak ~/sites/example.com
    7. Restore database to new database name set up in the Web App manager interface through phpMyAdmin
    8. Copy the site config.php (or whatever the name is) from example.com.new to example.com

    Done.

    I hope that Site5 fixes the issues with moving addon domains in the Web App manager ASAP. In the meantime the above may get the job done.

    • Hi Marty,

      Thank you for your input on this. The steps in this article are correct, however, and I have confirmed this with my own account. I am curious if you have encountered any errors while following these steps? If so, I would recommend contacting our support team with that error, as it should not be happening.

Money Back Guarantees
Click to verify BBB accreditation and to see a BBB report.