Domains: How to Host a Domain Outside of the public_html Directory
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…
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.
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.
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.
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.
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.