Sophisticated, Lightweight and Simple

Jump to docs navigation
Edit on GitHub

Note: You are currently reading the documentation for Bolt 3.0. Looking for the documentation for Bolt 3.2 instead?

Howtos » Running Multiple Bolt sites from one source directory

When running multiple sites on the one host, it is sometimes advantageous to only maintain a single directory for Bolt itself, and have each site in a separate directory using the same Bolt install. This is known as a multi-site set up.

This approach may have several advantages:

Set up base install

First thing that needs to be done is the set up of the core Bolt files in a central location, outside of the web root.

In this HOWTO we're going to use the location of /var/www/bolt-private/ but that is entirely up to your own needs.

In this example, we're going to create the Bolt project into the /var/www/bolt-private/ directory and install the vendor libraries with Composer:

$ cd /var/www/
$ composer create-project --no-install bolt/bolt:^3.0 bolt-private
$ cd bolt-private
$ composer install --no-dev --optimize-autoloader

Individual site set up

Each virtual host site you set up will need a few things:

Site directory set up

In this HOWTO we're going to install each Bolt site in a directory under /var/www/sites/, the first one in /var/www/sites/my-sites-1.

Create and navigate to /var/www/sites/my-sites-1:

$ mkdir /var/www/sites/my-sites-1
$ cd /var/www/sites/my-sites-1

Now create the required directories:

$ mkdir -p app/cache app/config app/database extensions files theme

Create a symbolic link to Bolt's templates:

ln -s /var/www/bolt-private/app/view/ app/view

Install a theme

For this HOWTO, we'll just use the default base-2016 theme and files. Copy the base-2016 directory into your site's theme/ directory:

$ cp -a /var/www/bolt-private/theme/base-2016/ /var/www/sites/my-sites-1/theme/
$ cp -a /var/www/bolt-private/files/* /var/www/sites/my-sites-1/files/

Site root index file

In the root of the sites web directory, create the index.php file and add the following:

$app = require_once __DIR__ . '/app/bootstrap.php';

Create the application bootstrap

Next, create the site specific app/bootstrap.php file and add the following:

return call_user_func(
    function () {
        // The full path to the core Bolt files
        $source = '/var/www/bolt-private';

        // The full path of the individual site
        $site = '/var/www/sites/my-sites-1';

        require_once $source . '/vendor/autoload.php';

        $configuration = new Bolt\Configuration\Standard(dirname(__DIR__));

        $configuration->setPath('root',    $source . '/');
        $configuration->setPath('app',     $source . '/app');
        $configuration->setPath('apppath', $source . '/app');

        $configuration->setPath('config',           $site . '/app/config');
        $configuration->setPath('cache',            $site . '/app/cache');
        $configuration->setPath('database',         $site . '/app/database');
        $configuration->setPath('extensionsconfig', $site . '/app/config/extensions');
        $configuration->setPath('extensionspath',   $site . '/extensions');
        $configuration->setPath('files',            $site . '/files');
        $configuration->setPath('themebase',        $site . '/theme/');
        $configuration->setPath('web',              $site . '/');


        $app = new Bolt\Application(array('resources' => $configuration));

        return $app;

You just need to edit the $source and $site parameters to set them to the correct directory locations for your individual site.

This is the one file you need to change for each site you set up using this configuration.

Setting up Nut

As a final step, each site will require a specific Nut command file should you wish to use Nut.

To enable this, create the app/nut file and add the following:

#!/usr/bin/env php

$app = require_once __DIR__ . '/bootstrap.php';

$nut = $app['nut'];

Finally make the Nut file executable:

$ chmod +x app/nut

Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on IRC.
Spotted a typo, or have something to add? Edit this page on GitHub.