Drupal 7 Multisites Migration: Different Domains to Same IP address No host file

Background:

The site is running Drupal 7.  User wants to have a UAT sites for that, but they don't want to change their host file because it is troublesome.

So I make some key-points on how to do it and I want to share it here.

Let's begin.

.htaccess file:

Make sure you .htaccess file DID NOT have any rewrite rules that redirect user to particular sites.  In my case my .htaccess file have these line:


I need to comment it out in order to make things work.  Pay attention to that.

settings.php

As you can see, under htdocs folder, I have 1 sub-directory for this Drupal 7 site.  And within this Drupal 7 site, I have 3 sites.  So when a user goes to:

  • subdomain1.domain.com
  • subdomain2.domain.com
  • subdomain3.domain.com
They will be redirected to different folders.

* I did not set $base_url in settings.php (this is commented)
* Make sure in your settings.php $databases var, set the 'prefix' value in your array.  Reference here.
* Yes I DID NOT set $base_url on ALL settings.php in sub-directories.  But I have different 'prefix' key in database connection string in ALL settings.php in sub-directories.

sites.php

Originally I don't have this sites.php in sites/ directory.

However, I copy example.sites.php and rename it to sites.php.  Then I add the code on the left.

Actually in example.sites.php it has a very detailed description on how to use it.  You can take a look.

Remember, sub1.com, sub2.com and sub3.com is a DIRECTORY NAME, not domain.

My directory structures is now (Blue is directory name):
  • htdocs/drupal/sites/all
  • htdocs/drupal/sites/default
  • htdocs/drupal/sites/sub1.com
  • htdocs/drupal/sites/sub2.com
  • htdocs/drupal/sites/sub3.com
  • htdocs/drupal/sites/sites.php
  • htdocs/drupal/sites/README.txt
  • htdocs/drupal/sites/example00.sites.php << I rename this file to avoid any confusion

now-dns.net

In this case since I don't know how to use IP in sites.php, I use a free dynamic dns service called now-dns to create a temporary mapping of domain and public IP.  I create 3 DNS record: sub1.now-dns.net, sub2 and sub3.

vhosts.conf


This is my vhosts.conf file used by Apache 2.4.  As you can see, all DocumentRoot are the same.  And make sure your ServerName points to diffferent domain.

Finally, clear Drupal cache

My situation is: I have 1 DB that hosts 3 different sites, so in order to clear Drupal site cache, I use phpMyAdmin.

Yes I know that you can use drush or other tools, but I prefer using phpMyAdmin.

Here is how to do it:
  • First, run show tables like "%_cache_%";
  • Copy the list of tables in your text editor.
  • Add "TRUNCATE" before the table name to truncate the table.  (Remember, it is TRUNCATE, not DROP)
  • Run it all in phpMyAdmin
My example queries would be like:
  • TRUNCATE sub1_cache_update;
  • TRUNCATE sub1_cache_variable;
  • TRUNCATE sub1_cache_views;
  • TRUNCATE sub1_cache_views_data;
  • TRUNCATE sub2_cache_block;
  • TRUNCATE sub2_cache_bootstrap;
  • TRUNCATE sub2_cache_browscap;
  • TRUNCATE sub2_cache_field;
  • TRUNCATE sub2_cache_filter;
These are not all queries, but just to show you what I did.

Then I RUN IT ALL in phpMyAdmin.

And you are done!

Hope it helps someone.


Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

How to fix fancy box/Easy Fancybox scroll not work in mobile

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services