Multiple sites with the same codebase

Status
Not open for further replies.

matthew1471

New member
May 13, 2007
242
0
0
Bournemouth, UK.
I have a network of 6 sites (with more in the pipeline), which all use the same code base, but have different css files for layout and database for data and logging etc.

Each site/domain has it's own ip and account on my vps. As the network grows, it's becoming a pain to upload new php files manually to each ftp account, so I'm trying to come up with a way of

1) automating the upload of any updated php files to each different ftp
or
2) doing away with all the accounts, and just have a single account, but have a config file which says "if domain = yyy use yyy.css and yyy.database"

Has anyone done anything like either of these? Any advice would be great.
 


Kinda depends on how you're hosting the site and what is built in, but in PHP I typically do something like this:

Code:
    $httpHost = $_SERVER["HTTP_HOST"];

    switch ($httpHost) {
  case "dev.somesite.com" :
  DEFINE ("CONFIG_NAME", "dev");
            break;

        default:
  DEFINE ("CONFIG_NAME", "live");
  break;
    }
Then where ever I need to so something specific to a particular host you can check to see which host it is. I use it to control which database is connected to for the dev/live site, but you can do it for other things too.

Mubs
 
But I think he's talking about using a config file to provide 'tokens' for each different site.

You could do this many different ways. Some are complex and some are really easy. It depends on your needs. I could help you come up with a completely automated system if you wanted to but here is the nickel version.

Using a properties/config type file and the php 'require()' function.

Let me know if that helps.

Code:
//contents of properties_file.php
$page_title = "My super spiffy new site";
$page_description = "My eBook on how to Make Buckets of Money While You Watch The Flintstones or Sleep";
//end of properties_file.php
 
 
//contents of index.php
<?php require ("properties_file.php");
<title><?php echo $page_title; ?></title>
<H1>This is my cool site about <?php echo $page_description; ?></H1>
//end of index.php

You could then make sure that each 'variable' portion of your sites, reference the exact same PHP variable to ensure your content is specfic to the site it's displayed on.

What's cool is that a new site only requires the domain, host, baseline code, and a new properties file be created. Very easy to put on 'autopilot'. :)

Crap, I should be hire myself out sometime. :)

Write once.....deploy many!

PM me or reply here if you have any questions.
 
I did the same recently (but mine are all on the same IP). I have 45 URLs using the same code base. I have an internal array that I pull from based on what is in _SERVER
 
mattgatten - sorry, you're on the wrong track, but thanks anyway!

patrick24601 - congrats, you're on the right track, have a prize :)

I'll start having a look at how it would work with _server now I'm home from the day job.

The difficult bit is going to be the differing ip's I think.
 
Well thanks for the 'wrong track' comment.

You can write all the if statements you want but it's no different than each site having it's own config file. However, you don't have to sniff for the server, ip, etc. Especially if you're just using it to connect to the DB or select the correct css. The CSS should actually use the same name on each site and never change. Uploading extra db connection data and css files to only be selected by a php script is pretty inefficient and requires you to upload them all to all the sites. (Hint, Dreamweaver does this for you). Just give them each their own config just like wordpress and every other php software package does. I said that was just the easy way. You could use Apache Ant to upload all your files automatically from your local PC or copy them all around if you wanted a high level of automation. But thanks anyway!

Maybe your questions should have been, how to I use PHP to pull the IP address of my site. Done and done.
 
Since you are using a VPS, you could store all your common pages in an external directory and then create symbolic links to those files every time you set up a new site.

At the shell prompt, enter:

ln -s target_filename symlink_filename

to create the symbolic link. Also, make sure you enable "Options FollowSymLinks" in your Apache config file.
 
Status
Not open for further replies.