I need to sequentially develop multiple Drupal sites.

For example:
1) I'm building and testing SiteA using the Drupal development tools
2) Now I want to stop working on SiteA and switch to working on SiteB, which is completely different and independent of SiteA
3) After working on SiteB for awhile, I want to switch back to working on SiteA

Note that this is not what the Drupal documentation calls "multi-site." I only want to work on one site at a time, serving it from localhost. It's for development only, not for "live" sites.

Pre-Drupal, I switched development targets by swapping file sets in and out of the htdocs directory. I'd prefer to swap Drupal targets in a similar way. I won't do this very often, so the extra complexity of tools like Drush and phpmyadmin is not necessary.

Obviously I don't want to re-install Drupal each time I swap the target.

I also want to have a MySQL DB that is not shared between the targets. That is, I want to swap the DB's in and out when I switch targets - each target should have its own DB (mainly to avoid name collisions in the DB).

All targets will use the same Drupal environment, themes, modules, etc.

So what folders and files do I move around to swap development targets? This should be simple, but searching the Drupal forums and documentation has so far been fruitless. As often happens, I'm probably not looking for the right terminology.

Any ideas? TIA.

MacOS X 10.8.5, XAMPP 5.6.20, Drupal 8.1.0

Comments

onejam’s picture

"All targets will use the same Drupal environment, themes, modules, etc."

Multi-site setup is what you need since you can share the same codebase but run both sites with separate DBs so you can store different data.

https://www.drupal.org/node/1682040

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

Jaypan’s picture

As digital construct has said, if you want to use the same code-base, then multi-site is the way to go.

Your other option is to create XAMMP subdomains, use them instead of localhost, and have multiple sites on your local server. Then you don't have to swap any files or anything. In fact, even if you do use multisite, you should be doing this. Only using localhost, and swapping out files everytime you want to change projects is an inefficient development methodology.

jfbart’s picture

Thanks for your responses, digitalconstruct and Jaypan.

It looks like I didn't explain this properly. SiteA and SiteB in my original comment are completely separate and different websites. There is no common "code-base" between them. Only the Drupal development tools are common.

Terminology is a problem here. If we were talking about a traditional compiled application, i.e., sourceCode->compile->objectCode->link->application, then everybody knows what those terms mean. But in the Drupal environment, the Drupal code is generating other code (php, css, html, etc.). So what does the term "code-base" mean?

I definitely do not want to use the multi-site setup. It's too complicated for what I need to do.

Swapping folders and files is simple and efficient if I use an alias in the right place.

Poking around, it looks like all I have to do is swap htdocs/sites/default folders, which contain the files folder and settings.php, restart MySQL and maybe Apache, then browse localhost. The settings.php file points to the database name, user name, and password, so swapping settings.php swaps the database.

I haven't tried this yet. What do you think?

Jaypan’s picture

I think you're making things difficult. I already told you how to do it in my last post. Use subdomains.

what does the term "code-base" mean?

Drupal is made up of three things:
1) Database
2) File system - aka code base
3) Uploaded and/or generated files (usually sites/default/files folder)

the code base is the Drupal source code, as well as any modules and themes you have added.

jfbart’s picture

This turned out to be simpler than I thought. Here is how to do it if you want to try it.

Drupal considers the current site to be defined by the files folder and the settings.php file, both contained in the htdocs/sites/default folder. So you can maintain multiple default folders inside sites, each representing a different site under development. To switch to a different Drupal target, change the current site's default folder name to some other name, change the different site's folder name to default, then browse localhost.

For example, suppose I'm developing SiteA and SiteB. The sites/default folder contains the files folder and settings.php file that defines SiteA. I have another folder in sites, named default_SiteB that contains the files folder and settings.php file that defines SiteB. If I browse localhost at this time I will see the Drupal development UI for SiteA. To switch to developing SiteB, I change the default folder name to default_SiteA, change the default_SiteB folder name to default, browse localhost, and I will see the Drupal development UI for SiteB.

Suppose I now want to begin developing a new site, SiteC:
1) I change the name of the default folder in sites to default_SiteB
2) I create a new default folder in sites.
3) I copy the default.settings.php file (which was in the original Drupal download of sites/default, don't delete it) into the new default folder.
4) I change the name of the new default.settings.php file (just copied into default) to settings.php.
5) I create a new files folder inside the default folder.
6) If I now browse localhost, I will see the Drupal UI for a new website. I can now switch between developing SiteA, SiteB, and SiteC as described in the paragraphs above.

This is a very simple procedure. It takes far longer to explain it in text than to swap the folder names, especially in the graphical file browser that most of us are using. For most developers, this is simpler than setting up multi-site development or using subdomains.

In case you're wondering, your MySQL database is automagically swapped by this procedure, since variables in settings.php point to the current database. If you look in xampfiles/var/mysql you will see the database folders for all the sites you are developing.

Note that these is no need to restart MySQL or Apache when switching targets in this way. It all "just works."

It's apparent that Drupal was designed this way. It's probably documented somewhere on drupal.org, but I haven't yet been able to find it.

Jaypan’s picture

It's apparent that Drupal was designed this way.

No, it just happens to work that way. Drupal was design for multisite, which with subdomains would be a lot simpler to maintain.

onejam’s picture

If you wanted to compare each site side by side, how would you do that? this is why you should setup subdomains using virtual hosts. http://jonathannicol.com/blog/2012/03/11/configuring-virtualhosts-in-xam...

Also, isn't just easier to switch between sites using subdomains?

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

Jaypan’s picture

Also, isn't just easier to switch between sites using subdomains?

Much easier.