views:

88

answers:

5

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, i currently duplicate the files each time i create a new site and uplaod different css and images.

What would be the best practice to simply this into 1 main location for all common files?

Here is my current structure for each site:

/home/ftpuser/public_html/commonfile1.php
/home/ftpuser/public_html/commonfile2.php
.....
/home/ftpuser/public_html/commonfileN.php
/home/ftpuser/public_html/commonfolder1/
/home/ftpuser/public_html/commonfolder2/
.....
/home/ftpuser/public_html/commonfolderN/
/home/ftpuser/public_html/css/
/home/ftpuser/public_html/css/mycssfiles.css
/home/ftpuser/public_html/images/
/home/ftpuser/public_html/images/myimages.jpg

How would i go about making all the common files located in 1 place for each site while still being able to have bespoke css and images.

Thanks in advance!

I am using Apache, PHP, Centos

Any suggestions?

A: 

If these sites are all on the same server, you can just include the files in your php includes.

then you can just include them as if they were in the same directory as your current php file.

Zack
+1  A: 

The most obvious solution, assuming that all the different sites are hosted on the same server/filesystem, would be something akin to:

+- common files (outside web root)
|
+- httpdocs (web root)
   |
   +--+- website 1 specific files
   |      |
   |      +- images (etc)
   |
   +--+- website 2 specific files
          |
          +- images (etc)

With the above diagram, all you need to do is include the relevant files from the shared location, and override/overrule for the purposes of site specificity using the site-specific files (whether stored inside, or outside, of the web-root).

If your sites are all hosted across different servers then it gets a little more complicated, since any common files would have to be hosted somewhere in the web-root (accessible via http). This isn't ideal, though there's nothing stopping it working, but in terms of bandwidth usage and issues with cross-site security, it's likely to be problematic.

With Virtual Hosts, you're at something of a halfway house between the two options; so long as they can all access the same document root you're still able to use the includes (as suggested by dland elsewhere in these answers).

David Thomas
As stated above, it sounds like you need a common lib directory for shared files. Then you can patch any bugs in the common code in all sites, without having to replicate this out across 50 other locations.
Greg K
A: 

I think you can just #include the files that you need from the main folder, you will have to make it accessible from all the sites (using soft links will cause the server to think they are in each site's directory)

Using soft links will make it easier from the paths concerns, and you won't need to use paths "outside" your httpdocs directory.

Dani
+4  A: 

I would have your 50 virtual hosts all using the same DocumentRoot. That way you guarantee that all sites will be using the same common files.

To pick up different css and image directories, use the Alias directive to point to explict directories for each VirtualHost.

dland
Yep virtual hosts solve this well.
Xepoch
I have done this..DocumentRoot /home/corefiles/public_htmlAliasMatch /testme/(.*) /home/ftpuser/public_html/testing/$1Problem is that ftpuser doesn't have permissions to read corefiles files. Not sure how to fix this. (testme/file.css works great though!)
Lizard
i'm interested in this too, what is the error that you're actually getting?
seengee
After some tweaks to the httpd.conf I have solved the issue, now i am confronted with another!
Lizard
A: 

If they're on the same server, you could just symbolic link the files:

ln -s /home/ftpuser/public_html/commonfile1.php /home/ftpuser/public_html/commonfile2.php

This breaks down in a shared hosting setup where different users (file owners) are involved.

Tim Lytle