Multiple sites using 1 code base, best setup to be able to update all sites at once for core issues, yet each site has it's own customizations?

Viewed 111

I have an app built on laravel and am using Bitbucket to manage versioning. Currently I'm running multiple sites from this one code base/branch. I'm wanting to have the ability to change the colors for each site as well as add some custom code for some of the pages. There are core parts of the site that will never change unless all the sites need to be updated. What is the best way to set this up in Bitbucket so that if I need to make an update to the core code and push it to all the sites while having the ability to customize certain portions of each site?

2 Answers

I’m in a similar boat and I solved this by creating a new value in the .env file: APP_BRANDING, which is different for each site. In the config/app.php file I have a line like this:

'branding'=> env('APP_BRANDING', 'default');

Then I can check what the value of config('app.branding') is in the code, and (for example) change the footer based off its value.

You don’t need to have just one value for this. It may make more sense for you to have multiple depending on what changes between sites.

You shouldn’t be saving the .env to your version control, so you shouldn’t need to do anything different for deployment.

This is the approach I did with a similar project. It's especially useful, if the amount of customization's is rather huge and includes many files.

I have a folder structure like this (not all actual files and folders are listed here, just important ones):

core/
  .git
  app/
  config/
  database/
  public -> ../design/public/
  resources -> ../design/resources/
  routes/
  .gitignore
design/
  .git
  public/
  resources/
  .gitignore

So I have two main folders core and design. The core folder has symlinks to public and resources located in the design folder. Both folders have their own git repository. You don't even need to exclude public and resources in the .gitignore of the core folder, because git will just keep track of the symlinks not their content.

Of course you can also move single files like special controllers, configs, database seeds, etc. to the design folder as well, if they're not part of the core components of your app.

On your server(s) you deploy the app in the same folder structure. You pull one repository in the core folder and the other in the design folder. You can freely work on the core repository and push the updates to all servers. And if you have design updates for sites you can work on the design repository and push that to a certain site.

Hope you could follow my explanation - for me this scenario works pretty well!

Related