In February 2006, I found Drupal and decided to give it a try. Since then, I have implemented five drupal sites of my own and three for clients, some independent of each other and some that share data. Between then and now, I have done a lot of research, testing, trying, trouble-shooting, and designing.
I have decided to share some general processed used to implement certain functions in these sites. Click-by-click procedures are not included as implementation environments differ (a big lesson learned over the past year).
Note: These steps were written to Drupal 4.6 but I still use them with D6 when I have trouble with the regular install process. I have a backup db export from an initial D6 setup. When D6 doesn't want to behave, I revert to the D4 process.
Compared to the process of creating multiple sites that share a database, this process is fairly simple.
Databases: Assuming each of your sites will have its own database, you need to create enough drupal databases to match the number of sites you want. Perform the following processes:
1. Login into your database admin area; I use phpMyAdmin. Create as many blank databases that you need (given the number of sites you need). Give them all unique names of course. Mine are idcmi1, idcmi2, idcmi3, etc. Not a naming convention I recommend. It is hard to remember which one goes with what site. I have little reminder postit notes all over my desk ;-)
2. Locate and install the default database that comes with the version of Drupal that you have installed. Look for it in the default installation files that come with Drupal, in a directory called database. The file name is database.mysql.
3. From your database administration area, enter the first blank database and import and expand the database.mysql file. In phpMyAdmin, I click on the SQL tab and on this screen I have the option to browse for a file to upload and expand.
Site directory: Now that you know the database names and assuming you know the domain names of the sites you are creating, do the following:
1. Locate the directory called sites on your server. In there you have a folder called default. Make several copies of this directory and its contents: default, default2, default3, default4, etc.
2. Next, change the name of one default directory to match one of your domain names. For example, my site is idcminnovations.com so I changed my default directory to be EXACTLY that (including the period and com, no spaces of course). Continue this process until all directories are named exactly the same as their assigned domain. If you are using subdomains like idcminnovations.com/book, then use idcminnovations.com/book as the directory name.
Site setup: If one of your sites is already up and running, then you know what the following steps are asking you to do. Within the sites/domain directory, there is a file called settings.php. In this file, you set the URL and database access.
1. Edit the settings.php file so that the url referenced in this file is consistant with the domain name you used as the name pf the directory.
2. While in edit mode, update the reference to the database. Change the database reference to match the database that will support the site. For example, is db1 is to hold the content for domainname.com, then set the database to be db1. On my server, the login and password for the databases are the same as they are all hosted within one occurance of MySQL on my server space. So, this process might be a simple edit for you if your first site is already up and running.
Site configuration: Now it is time to create your login for each site. Because they all have their own fresh clean database, you need to configure each site just like you did the first.
1. From a browser, enter the domain name of your second site (assuming you have already done this for the first). Remember it takes time for DNS servers to refresh so if your server is remote, be patient.
2. Create your login and enter the site.
3. Enter the admin section and start configuring the settings, themes, etc.
Conclusion: At this point, setting up each site is the same as you have done before when setting up a single site.
The guidance provided below assumes:
The processes that differ are the database setup and the settings.php configuration. This article focuses on the database setup. There are two parts to this process: create new tables and edit tables.
Step 1: Create new database tables
This process assumes that you are using all the same database tables as the primary site except four: blocks, boxes, menu, and cache. The primary web site will use these original four tables. The secondary web site will have its own version of each. The names need to be changed. Drupal uses a table prefix function such that the four tables will have a prefix added to each. For example, secondsite_blocks, secondsite_boxes, secondsite_menu, and secondsite_cache.
To create additional tables in your Drupal database, you need to be able to access your database and create tables. If you performed your own install of Drupal for the primary site, you have access to a tool such as phpMyAdmin. Or, you have installed the dba.module, you can use that interface. Choose an interface and access the SQL/Query interface and get ready to copy the applicable SQL code from the database.mysql file.
Because there are different versions of Drupal, it is suggested that you use the create table SQL provided in the database.mysql file provided with Drupal. Open database.mysql in Notepad and locate the SQL for each table. Copy the SQL into the SQL/Query interface. Before you continue, edit the table name. If the table is the blocks table, change the name to secondsitename_blocks. Then execute the query. You can create all four tables at once or one at a time, always remembering to add the exact same prefix to the table name.
Step 2: Edit tables
Once you have the four new empty tables in place, you need to edit two tables.
First, you need to give the blocks table the default records. The easy way to do this is to export the default records that were created when you configured the primary site. Again, you can use whatever tool you want. The objective is to locate and copy the SQL that inserts a record. It will look like this.
INSERT INTO blocks VALUES("article","0","0","0","0","0","0","0","","");
There will be several of them. Copy them all and paste them into the SQL/Query interface. Before you execute the query, change the table name from blocks to secondsitename_blocks (to match the table name you use when creating the table). Execute the query. This will kick start your second site blocks and allow you to edit them and make them different than the ones in your primary site.
Second, you need to clear the cache table in the primary site. You need to use the empty command and can do this from your choice of database interfaces.
The guidance provided below assumes:
The processes that differ are the database setup and the settings.php configuration. This article focuses on the settings.php setup. There are several steps required in order to setup the settings.php file starting with its location, its creation, and its editing. There are four parts of the settings.php file that needs to be edited: database name, database prefix array, base url, and the variable overrides.
Step 1: Create your Drupal site directory
The first step is to create a directory for your secondary site. In Drupal, go to the sites directory. If you haven't changed the name of the default directory contained with the sites directory, change that directory to be the domain name of your primary site. For example, myprimarysitename.org.
Then create a new directory with the same permissions as the default directory. Name that directory using the domain name of your second site. For example, mysecondsitename.org. If you are using a temporary domain name, name the directory the temporary domain name. You will change it later when you are ready to go live with your preferred domain name.
Step 2: Upload the settings.php file
Now that you have an empty directory for your second site, you need to create the settings.php file. This can be done several ways. One way is to upload a version of the settings.php file into this directory. The version you choose can be a copy of the primary site settings.php file or it can be the default you got with Drupal.
In either case, the permissions associated with the settings.php file need to be the same as those assigned to the primary site settings.php file.
Step 3: Setup the database name
This is the same step taken when setting up the primary site settings.php file. This command should be exactly the same. If you did not configure the settings.php file, view the contents of the version located in your sites/default directory. Locate and copy the command line that looks like this but has your specific information versus this generic data. You should see your command line just beneath this one:
$db_url = 'pgsql://username:password@localhost/database';
Step 4: Setup the database prefix array
There are several suggestions on the drupal site as to how the prefix array should be configured. The following is designed to accomplish the task described here AND work in Drupal 4.6.x.
Beneath the database url command line, you need to insert these two command lines:
$db_prefix = array(
'default' => 'secondsitename_',
Then you need to list all the tables your two sites will share, using the syntax shown here:
'access' => '',
'accesslog' => '',
);
To ensure all works correctly, all the tables need to be listed. A typical installation of Drupal 4.6.x will have about 50 tables. At the end of the list, be sure to include the );
If you add tables as the result of adding a new module, you need to add the new table name to this list if you want the module function to work on each site.
Step 5: Setup the base url
This is the same step taken when setting up the primary site settings.php file. If you are not familiar with this command line, you are looking for a line like this:
$base_url = 'http://domainname.com';
This is the domain name you used for the directory. It is the one you want to use while setting up your second site. Remember that this might be a temporary domain name. Recall, if your already existing second site domain name is mybestsite.com, maybe you buy a one year subscription to mybestsite.net, or the like.
Then one you are ready to go live with your preferred second site domain name, you will eidt this command line accordingly.
Step 6: Setup the primary variable overrides
The last part of the of the settings.php file you need to edit is the section called "Variable overrides." In this section you will use the command line:
$conf = array(
And you will follow this command line with the variables that you wish to override. For example, at a minimum you will want to use these two lines:
'theme_default' => 'friendselectric',
'site_name' => The name of my second site typed here', );
These two variable will provide a unique theme, one different than the primary site, and a unique name for the theme to use. This is the bare minimum needed to make the same content look different.
Optional step: Setup other variable overrides
There are other variables that you can override as well. If you want a list of variables that used in Drupal, access the database table called variables. Not all variables are easy to override.
To accommodate a unique front page, you can create a unique mission by adding this command line:
'site_mission' => 'type here the text and html code you want to use for your mission.',
A unique mission statement will allow your front pages to be different to an extent, allowing each site to show the same nodes promoted to the homepage.
If you want the second site to simply have its own front page and not show the promoted notes of the primary site, you can override the "site_frontpage' variable like this:
'site_frontpage' => 'node/1',
The node/# you use corresponds to the content node you created to be the "homepage."
Of course, both sites can have their own frontpage thus eliminating the ability to promote content nodes to the front page. For the primary site, you would edit the admin/settings/ feature and assign a node to the "default front page" field on the settings page.
Using Drupal themes out-of-the-box might not be enough to make the two sites unique enough. The next step is to customize the theme into something you can call your own. Some the themes require engines to run while others do not. In either case, there are typically two parts to a theme that you can customize, the file that calls out the layout or structure of the site pages and the file the defines the styles.
In this scenario, we are going to assume the theme does not require an engine.
Step 1: Edit the site structure
There isn't a lot to do with this file. We will use this to decipher which styles in the CSS file are used to change the look and shape of the structure file.
Step 2: Edit the CSS
This is the file that dictates what everything in the structure looks like. It also changes the size and shape of the structure components.
Step 3: Create new images
The creation of the new images for your unique look isn't the hard part. Knowing how large to make them and how the theme calls them can be the tricky part. Not all themes treat the design images the same.
The key to remember is, some themes require a file name of "logo.jpg" or "logo.gif" and they look for that file in the files directory. If you have two site using similar theme structures, you might need to get clever with the design images and where they are stored. You might need to edit the structure file to look for a different file name or you might need to use the CSS to call the image you want. OR a combination there of.
Another way to customize a Drupal site is via its navigation. The menu structure that we will customize is the blocks. The primary links created using the admin/settings feature are shared by each site so they need to be common to each site. You want this to encourage a similar feel between the sites.
You can use the blocks to create custom navigation. To do this, you need to ensure that your taxonomy is set up to let you classify your records for use in one site versus the other, if needed.