Splitting common D6 code base into 2 totally separate sites

Events happening in the community are now at Drupal community events on www.drupal.org.
mobcdi's picture

I am hoping the drupal community in Ireland will have come across this before and can help guide me on how to do it.

I have 2 D6 websites using a common code base and would like to split them into 2 separate sites with their own modules and core files. That will let me upgrade them independently and only include, activate and upgrade the modules that each site actually needed

Is it possible to do this?
I was thinking the backup/migrate module may be useful in this case but not sure if its just as easy as that

Comments

It is possible, and not too hard.

EoinBailey's picture

I have re-arranged modules and code bases several times. Just make a copy of everything to split the sites apart. Delete the 'default' folder in the second site and create a symlink named default that points to the directory for the second folder. E.g.

if the sites directory has a structure:

sites
- all
- default
- example.com

you can just delete the folder 'example.com' in the domain that the 'default' directory applies to - your first domain and site is now on that core and module base.

In the copied folder (that I assume is in the correct location for the second domain 'example.com'), the sites structure will be

sites
- all
- 'default' (symlink to example.com directory also in sites)
- example.com

Using a symlink means you won't have to change around files and images stored inside the 'example.com' directory.

Just delete the modules in each respective sites install that you don't need.

Also, you can move modules around between 'all/modules' and 'default/modules' with no fuss. Clear the cache, run cron and you should be good to go again (Drupal will automatically find them in the new location and use them).

Bingo, two sites now using their own versions of core and modules.

If you have to change the database server too you will want to export the tables for the second site, import them into the new database and update the 'settings.php' file to point to the new database (if you don't do this it will probably still work and run off the old database, it depends on the server config). Backup migrate will let you export the tables for each site and download a file representing them. If you are using MySQL, PHPMyAdmin has a simple 'export' and 'import' feature too.

Hi Eoin, Thanks for replying.

mobcdi's picture

Hi Eoin,

Thanks for replying. I have to say Unix isnt my strong point so talks of symlinks was already putting me on edge before i had a look at the site structure to see if it matched up to your description above.

Some background might also help. I have a production site with 2 sites (production.tld & subsite.production.tld) sharing off the same codebase and a test site (test.tld & subsite.test.tld)which is a copy of the production site to play around with modules and config changes before making changes to the production site.

My concern is that when I check the sites folder on the production account I see folders (all, production.tld, default,files & test.tld) test.tld and default have a link target of ...production/public_html/sites/production.tld
The testing account sites folder has (all, production.tld, default, files & test.tld)
target of testing/public_html/sites/production.tld

I would like to not mangle production why I try splitting the test site into independent sites but would also like to completely decouple all sites and end up with 4 completely independent drupal sites (no sym links if possible) without first checking to make sure my production and test sites are independent of each other.

I couldn't see in the settings.php files where it says which sites are actually running on each account. Can you help clear up my confusion

Symlinks, sites structure, and settings.php files

EoinBailey's picture

I see two issues, one is the use of symlinks. First, they are exactly like shortcuts, no need to worry about them. There are GUI ways of making them in the exact same manner as a shortcut, the command-line method is a single line though:

ln -s ~/drupal/sites/example.com ~/drupal/sites/default

That will give you a symlink called 'default' that links to 'example.com'. If you are not using the 'files' directory in the 'example.com' directory of your second production site you can probably just rename it to 'default' and be all good to go. If you are though, the other option is to change the address of these files in the database. I have done this before, it's a pain. I can't recall where to look for these though, since moving to using symlinks it hasn't come up. Someone else might help with that.

The second issue I see is the organisation of the 'sites' directory. Let's ignore the test set up, changing that is the same as the first one. I'm a little confused by your description though.

sites
    - all
    - production.tld
    - default  - links to 'production/public_html/sites/production.tld'
    - files
    - test.tld

default - links to 'production/public_html/sites/production.tld' - what do you mean by 'links to'? It sounds to me like you mean a symlink, but since you said you dont like them, I am not sure now. That being the case, how is there two sites running of this codebase? The sites directory needs a directory per website, based on your info, I would have expected to see something like this:

sites
    - all
    - subsite.production.tld
    - default  (this is the default website - production.tld)

There should also be separate 'settings.php' files per site, i.e. one in the directory 'default' and one in 'subsite.production.tld'. There is no simple way to know what site is running by looking at the settings.php file, it's main job (in this context) is to connect to the database where your content is pulled in. The db_url line will tell you what database it is connecting to and on which server.

Does production.tld display different information that subsite.production.tld? I could be missing something, but without multiple settings.php files I don't see how you could have sites displaying different information (not without major changes to the settings.php file anyway).

Sorry for the confusion I was

mobcdi's picture

Sorry for the confusion I was looking at the folder structure using a GUI that showed the target of the shortcuts/symlinks. An earlier view using a different system didn't show the difference between real folders and shortcuts. While I see the benefit of symlinks I would like to make the structure as simple as possible with each sites files in their own home folder including user files

I checked the setting.php files and found the 2
default/setting.php connects to production.tld database
subsite.production.tld/settings connects to subsite database

My plan of action is to
Put sites in maintainence mode
Full site backups (files and db's)
Remove the old symlinks in the production multibase that share the test multibase names
Full site backups again
***Subsite Move****
Create new account for subsite
Import old subsite db into new subsite db (web host creates database names prefixed with accountname)
Import old subsite files (wwwroot, etc) but removing all but the default sites folder
Edit the default/settings.php to connect to subsite new database
Move 'all/modules' to 'default/modules'
****Clean up mainsite*****
Drop the old subsite db
Delete the subsite entry in the sites folder
Move 'all/modules' and 'default/modules'
Clear Cache and Run cron


Clear cache and run cron for subsite
Bring all sites out of maintainance

Does that sound about right or did I miss a step with user files or settings used within drupal?

The only issue I see is the

EoinBailey's picture

The only issue I see is the location of files. Where are files stored for the subsite at the moment? The production site files should be fine, since they won't be moving and more importantly the URL for a file won't change. For the subsite this isn't true. Some modules will use the location of the files database you enter as part of the URL, but some (image certainly used to have this problem) modules hardcode the URL for each file at the time of creation, if this is the case with any of the files you have changing the structure will cause a problem.

Started the move and seem to

mobcdi's picture

Started the move and seem to go well in so far as the subsite is displaying the site maintainence message and an error about Open basedir

pen_basedir restriction in effect. File(/home/OLDHOME/private_files/subsite) is not within the allowed path(s): (/home/NEWHOME:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/NEWHOME/public_html/includes/common.inc on line 1840.

warning: is_dir() [function.is-dir]: open_basedir restriction in effect. File(/home/OLDHOME/private_files/internal-cdi) is not within the allowed path(s): (/home/NEWHOME:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/intenpro/public_html/includes/common.inc on line 2194

I also cant log in because subsite.domain/user page does'nt exist

I searched the tables for listings of home/OLDHOME and replacing it with home/NEWHOME but the only entries left are "blob" that the phpmyadmin doesn't recommend editing in the following tables

1 entry in cache
1 entry in cache_content
5 entry in cache_menu
3 entry in sessions
184 entry in watchdog

Clear everything from the

EoinBailey's picture

Clear everything from the cache and sessions tables - it's probably something in there.

Watchdog table can be ignored - no harm to clear it too though, the info in there will all apply to the last location of the site.

Thanks Eoin I am able to

mobcdi's picture

Thanks Eoin

I am able to login to mangled view of the site using the /?q=user/login url but get the error
warning: call_user_func_array() expects parameter 1 to be a valid callback, function....
repeating for a number of functions

The url's of the links look like clean versions of drupal ones
Is there a way to rebuild the cache using a non clean url because i get the 404 error?

If i add "//?q=admin" to my

mobcdi's picture

If i add "//?q=admin" to my url i can get the Administer By Task or By Module but again none of the links will direct me to their intended target

After a brain wave or in an

mobcdi's picture

After a brain wave or in an effect to dig myself deeper into a hole I remembered the .htaccess file so checked it out and the copy process did not bring over the contents of the file. After another while using the "old" htaccess file I found a drupal page that recommended using the default 1 from drupal setup files so I did that.

I also used phpmysqladmin to disable maitenance mode using the following commands
UPDATE variable SET value = 's:1:"0";' WHERE name= 'site_offline';
AND
DELETE FROM cache WHERE cid = 'variables';

From that I got an allowed memory usage exhausted by drupal error so increased the memory usage to 64M but now am getting a 403 access denied when I try to view even the home page of the site

any and all suggestions welcome

Did you delete everything in

EoinBailey's picture

Did you delete everything in the cache? The cache tables can be emptied entirely with no ill effects on the site (bar performance hits as the cache is rebuilt), backup and migrate module by default excludes all data from them in any backup.

Do you use clean urls on the site normally?

I'm assuming the 403 is the browser default, not a Drupal page, if that is the case I would say it is almost certainly the .htaccess file causing that.

I have had problems with transliteration and mimedetect modules when moving sites around too, that can sometimes give the dreaded WSOD - either of these modules in use?

With so many different errors coming up, it's time to minimise potential problems, I would remove all the contrib modules from the sites directory and all sub-directories as a start.

Another debug procedure, put in a fresh settings.php file and see if the default drupal install page comes up, if it does Drupal core is probably working.

NOTE: I always give my sites 128MB of memory - just to be sure.

Ahh, debugging. Code is a fickle thing, web-based even more so, and server-side where you can't access the server is the worst!

I thought i had everything

mobcdi's picture

I thought i had everything cleared out of the cache but using phymysql I truncated the cache tables and like a switch the site was back up, small matter of a few missing images but a massive improvement from yesterday so thanks for all the help Eoin.

I did move the folders modules, themes and extra back into an "all" folder in sites when i was getting all the other errors. The same folders already exist in default. Is it ok for me to delete them?

No worries

EoinBailey's picture

It should be fine to delete them, Drupal is pretty good at picking up on modules even when moved around. My strategy: do it, and if it completely stops working after clearing the cache and running cron, put them back - thankfully it rarely happens that I need to undo.

Before i go down that road I

mobcdi's picture

Before i go down that road I seem to keep hitting file/folder permissions because the site logo and favicon don't appear and when I run cron I get "open_basedir restriction in effect. File(/tmp/mysql.sock) is not within the allowed path(s): (/home/SITEBASE:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/SITEBASE/public_html/includes/file.inc on line 898.

Any pointers you can offer me?

I'm guessing your tmp

EoinBailey's picture

I'm guessing your tmp directory is set to an area that you don't have write permissions for - change that here: admin/settings/file-system

The site logo and favicon are most likely a separate issue, I would just upload them again for your chosen theme.

Got it all working in the end

mobcdi's picture

Got it all working in the end and learned a few things from doing it in case they are useful to anyone else

Don't forget to check the file backup has all the files including the htaccess content (not just a similarly named file)
Clear the cache including the views cache
File/Folder permissions and paths have to confirmed as well
Before importing the db to the new account run a find & replace to switch file path references but keep a copy of the original db just in case
Truncate the cache tables after you import the database just in case there are any glitches still left over

Thanks again Eoin for all your help

Ireland

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: