Welcome to Geeklog, Anonymous Saturday, April 20 2024 @ 09:36 am EDT

Question: How can I run multiple sites using one code base?

Answer: I have one core geeklog directory, running several sites. A few files have been separated out for each site so that they can be uniquely customized, but on the whole the sites all read the same set of core files in the one folder.

The main advantage of this is that when you make a change to a core file, the change applies to all of your sites, rather than you having to make the same change in each and every instance of geeklog. Much easier to upgrade that way. I'm considering changing this by using CVS and having multiple core geeklog folders instead, but for now I'll show you this way.
----------------------------------

First thing to do is unpack the tarball. I'll call the resulting directory geeklog-1.3.

At the same level as that directory, create dirs for each site, like site1/ site2/ site3/ etc. I'll use these names as examples.

Into each one of these site directories, copy config.php from the geeklog-1.3 directory. Then, in each site directory, create the following subdirectories:

backups/
layout/
logs/

Now, in geeklog-1.3/public_html/layout/ do the following:
ln -s ../../../site1/layout site1
ln -s ../../../site2/layout site2

Repeat for each site. (Whenever I say 'site1', assume that you're supposed to do that step for each site and substitute an appropriate string to designate each site.)

While you're in this directory, copy whichever themes you're going to use for each site into the layout/ directories that you just linked to, i.e. 'cp -rf XSilver site1' and so forth.

Now, in the config.php for each site, you will have to set your db settings, your paths, and your site settings. There are two ways to set up the database(s): if you are using multiple databases, one for each site, set $_DB_name to a different database for each site. If you only have access to or only want to use one database for all of your sites, then set $_DB_table_prefix to a unique string for each site, such as 'site1_gl_', 'site2_gl_', etc.

When you set $_CONF['path'], make sure it points to your geeklog-1.3 directory and not to the separate dirs where the site-specific config.php files reside.

Down in the settings that you don't normally change until after the site is up and running, there are a few you'll want to change:

$_CONF['path_log'] and $_CONF['backup_path'] should point to the locations of your logs/ and backups/ directories for each site, which should be in the same folders as your config.php files.

Set the filename in $_CONF['rdf_file'] to something unique for each site, but make sure it starts with 'backend/'. The RDF is an XML news feed that other sites can read. If you don't set this to a unique name for each site, all your sites will write to the same file.


For images a little more is involved, because the code will overwrite the path to the layout_url. So what you need to do is create a new variable in config.php and make code changes in lib-common.php

Create a new $_CONF variable in config.php and modify lib-common to use the new variable. Like so:

In config.php, right above where $_CONF['layout_url'] is set, add the line:

$_CONF['themes_url'] = $_CONF['site_url'] . '/layout/site1/';

and then change the layout_url line in config.php and the two places where it gets reset in lib-common to:

$_CONF['layout_url'] = $_CONF['themes_url'] . $_CONF['theme'];

And that fixes it. This won't come up in a normal installation unless you've changed the location of your layout folder, but this way makes sure that you can do that without problems.


Further down, you'll need to set $_CONF['cookiedomain'] in order for gl 1.3.8 cookies to work properly. If your site's url is http://www.site1.com:8080/main, for example, you'll want to put '.site1.com' here.

You shouldn't have to change any more settings than this in config.php to get your sites running.


Next, you'll want to edit lib-common.php. Assuming that each of your sites is at www.site1.com, www.site2.com, etc., Edit the line where it says:

require_once( '/path/to/geeklog/config.php' );

to the following:

$config_require_path = '';

switch ($_SERVER['SERVER_NAME']) {
case 'www.site1.com':
$config_require_path = '/path/to/site1/config.php';
break;
case 'www.site2.com':
$config_require_path = '/path/to/site2/config.php';
break;
}

require_once( $config_require_path );


Next, set the permissions on the following folders like so:

chmod -R 775 /path/to/geeklog-1.3/public_html/backend/
chmod -R 775 /path/to/geeklog-1.3/public_html/images/articles/
chmod -R 775 /path/to/geeklog-1.3/public_html/images/userphotos/

chmod -R 775 /path/to/site1/logs/
chmod -R 775 /path/to/site1/backups/

As in the documentation, if your site still gives you errors associated with these folders after you have completed the installation, you can try setting them to 777. Use 775 first, though. And even though backups/ is not mentioned in this part of the documentation, I always find I have to set its permissions in order to use the backup feature.

Finally, you'll want to direct each of your virtual hosts in your apache configuration to your geeklog installation, by setting DocumentRoot to /path/to/geeklog-1.3/public_html and restart Apache.


Now you're ready to start installing. In your geeklog-1.3 directory, do the following:

ln -s ../site1/config.php

Now go to http://www.site1.com/admin/install/install.php and follow the directions. Where it says 'path to geeklog,' use the path to your geeklog-1.3 folder and not the path to where your actual config.php file resides. When you are done with the installation, go back and delete the link to config.php in your geeklog-1.3 folder and create a new one for your next site, then do the next installation, etc. until you have done all of them.

----------------------------

That should be all you need to get several sites up and running using a single core set of files.

There is no guarantee that this is bug-free, but it's a good start. This process could also be extended, so you could have separate sets of language files for each site, for example. I only wanted to give you the essentials here so as to avoid confusion.

Contributed by gHack

Hits: 1030

FAQ » General » How can I run multiple sites using one code base?