Can 2 Domains Share Resources on a Shared Hosting Plan?


#1

I have two domains hosted separately on a Happy Hosting shared host. A lot of content on both domains is the same, so I want to have a shared folder in my account that both sites can access. For some reason, though, I am not able to do that.

Example:

My hosting account has 3 relevant directories: /home/username/website1; /home/username/website2; and /home/username/shared

When users to go www.website1.com, they are directed to /home/username/website1/index.htm. Within that page, I have a reference to a script at /home/username/shared/script.js. How do I direct the index.htm page to call the script.js script? On a normal setup, you would use <script src="…/shared/script.js">, but that isn’t working.

Checking the error logs, it says “File does not exist: /home/username/website1/shared” So even though I referred to one directory level higher than website1 (with the …/ portion of the src tag), the server is treating it as though I’m looking for a folder within the /website1 directory.

Dreamhost support says I should be able to access any file in my username’s directory and suggested that I use the absolute path to the file, but no matter how I try to address it, it doesn’t work. The error logs consistently show that I’m trying to access a subdirectory to /website1, even though I’m trying to refer to a separate directory on the same level as /website1. It really seems like it’s straight-up refusing to access anything outside of the /website1 directory.

Any ideas on how to accomplish this?


#2

Do you have a <base> element in your html <head>?

Is there anything in your .htaccess that is redirecting requests?


#4

I don’t have a tag, and I haven’t modified .htaccess since moving to Dreamhost. Where is the .htaccess file, anyway?

I have no issue hosting two domains on one shared hosting plan, I just want the pages in each domain to be able to access a shared folder.


#5

Dreamhost support says I should be able to access any file in my username’s directory and suggested that I use the absolute path to the file

I’m not quite sure where they are getting this from.

This really isn’t possible (I just tested to confirm). I believe the issue is the virtual host sets the domain that any relative references will refer to, hence this result:

The error logs consistently show that I’m trying to access a subdirectory to /website1, even though I’m trying to refer to a separate directory on the same level as /website1

No matter how you write it, it is always going to default to the website directory you are in.

If you are using PHP, you can probably work around this, by setting a DOCUMENT_ROOT variable, but there may be issues around this.

The simplest way would be to just create a subdomain of one of those domains and use it as a cdn. So you would have www.website1.com, www.website2.com, and cdn.website1.com. Drop any shared files in cdn.website1.com and call them using the full URL reference:

`

I can guarantee you that will work.


#6

The issue is that you are trying to escape the domain root via a public request, this is not possible.
htaccess will not allow this either, since this is a security risk.

As I see it, you have two options:

  1. Create a new subdomain, something like shared.clubapk.com and keep your shared files there, your script url would than need to use it as a full path: <script src="//shared.clubapk.com/script.js">
  2. Add an symbolic link via SSH so that your shared directory would look like a normal directory within your sites, your scripts will be available like they were part of the site to begin with <script src="/shared/script.js">
    For this your user needs to be configured as shell user, you can edit users here (link), after this you can access the ssh console via a program like PuTTY (google it) by connecting to your domain and using your username and password for the user under which the websites are hosted.
    Finally execute the following command to create symbolic links: ln -s ~/shared ~/website/shared
    (be sure to use the website directory instead of “website” within the command, as an example
    "ln -s ~/shared ~/clubapk.com/shared", you’d have to run the command for each website you wish to have access to shared resource.

Cheers,
Gene


#7

To answer the title question: Yes, you can have MANY domains and their subdomains all hosted in the same shared space. However… For each DH account we can create many Users, and each User gets its own /home/user space for sites. All sites under a given user compete for some amount of resources allocated per-user, so it helps to have sites under home/user1 and home/user2. All users within an account also compete for resources, so sites under user1 will compete for resources with those of user2. This puts limits on what can be achieved within shared hosting. The next step from there is to move the more important sites to VPS or dedicated DreamCompute so that they aren’t affected by over-use of the less important sites.

None of that is related to your technical challenges which others have addressed. I just wanted to set expectations based on your original question. HTH


#8

I have two domain in one share hosting … was work good and today noon one domain stop working other work ///
kapital3.net no working I stayed log in , I can add page, delete, add music … etc
when u visit website not working … half day I spend chatting with support and they promise some one will be fix …


#11

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.