Managing Multiple Websites With A Single Laravel Codebase

My team has recently put together a Laravel codebase that works great for multiple websites. Currently we are running them as an app that installs on a centOS7 profile.

Whenever a new site is required, we fire up a profile, and the code gets cloned in. The codebase depends heavily on packages (custom laravel packages). Currently every site pulls in all of the packages that we have developed. Currently the differences are 1) The .env file. and 2) The theme config files (which come from a package and I'll touch on later).

I want to be able to pull packages based on need, I don't want to pull in every package we've developed. My question is, is there a way around pulling in every package? I was thinking of removing the composer.json file from git and treating it like a config file? I also thought about generating the composer.json file.

Eventually we want to add CI/CD to the process and really automate this thing. I am really fighting to keep the codebase in one repository. Am I wrong? Should we split the codebase up, one repository per project that comes in? But then you have to consider that updates become a nightmare.

Currently, themes are pulled in as packages. Every site has all of the themes in the composer file. The app has admin users that can login and set a theme to active. Still, I'd like if it only pulled in the necessary themes resources.

Sorry if I rambled a bit, but I am wondering how to scale the application properly.

Thanks a bunch!

tldr; How can I run multiple websites using one codebase, while being able to specify different required custom packages?



I haven't actually tested this but you might be able to accomplish what you want by defining multiple composer.json files. Read more on defining other composer.json files

Then, in each composer.json file define a different vendor directory. Example:

    "config": {
        "vendor-dir": "plugins"

Next, on each install specify which composer.json file to install, From the docs:

By setting the COMPOSER env variable it is possible to set the filename of composer.json to something else.

Example from docs:

COMPOSER=composer-other.json php composer.phar install

Read more on specifying the environment.

Last but not least, you will have to bootstrap your website or application for the specific vendor directory:

require __DIR__.'/../custom-vendor-directory/autoload.php';

This can be customized in your application's index.php file. The original source.