BringMeAnother
BringMeAnother

Reputation: 627

Hosting multiple sites on server, sharing resources

I have a host that allows for multiple addon domains and my folder structure resembles this:

public_html
- site1.com
- site2.ca
- site3.tk
- codeigniter

The document root for each site are currently set as /public_html/site1.com, public_html/site2.ca, etc...

I use CodeIgniter on some of the sites. The codeigniter folder in public_html is the same folder called "system", which I have just renamed. I find that in the PHP code of the sites, I could have in index.php:

$system_path = '../codeigniter';

This would work on my test local server. I haven't tried yet on my host, but I think it should work there too. That seems like a good improvement in efficiency.

What I want to do now is to have the same kind of efficiency but with css, js, images and other front end assets. Naively, I tried putting things like this

public_html
- site1.com
- site2.ca
- site3.tk
- codeigniter
- js
- css
- img

In my pages I'd have something like:

<script src=/../js/app.js></script>

Now that I think about it, it obviously won't work or for client side assets.

The thing is I have build a development environment in which I'm comfortable with and I'd like to use it again and again with my new sites. I'm currently copying all those front end assets from old projects to new project, but they don't change for each project. I was wondering if there was a better way to host those static assets in a way so that it wouldn't be duplicated for each site. Perhaps there isn't and I should continue copying?

Upvotes: 0

Views: 136

Answers (2)

Cups
Cups

Reputation: 6896

Not sure about css and img, but for js assets I add this line to the virtualhost in apache.conf

<VirtualHost *:80>
// usual stuff ...
Alias /js /var/www/whereyourjsfolderis/js

You might want to do that for common css and image folders I guess

Alias /js /var/www/whereyoursharedfolderis/sharedcss

Upvotes: 0

Halcyon
Halcyon

Reputation: 57709

I don't think it's wise to share resources in the way that you describe, and this is partly from experience. If you couple multiple sites to one backend it means that you must upgrade all the sites when you want to upgrade one of them.

Duplicating them may seem wasteful but unless you have a really good reason for it I would strongly advise against it.

If you're looking to optimize performance there are likely other things you can try first.

Upvotes: 1

Related Questions