nativeInstallerdiscourse

Enable multi-site support

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

NOTE: The Approach A sections referred to below do not apply to Bitnami native installers. Users of Bitnami native installers should refer only to the Approach B sections.

Follow these steps to enable multi-site support:

  • Create a new database and database user for the new site. Execute the following commands at the server console, remembering to replace the DATABASE_NAME, DATABASE_USER and DATABASE_PASSWORD placeholders with actual values.

      $ installdir/postgresql/bin/psql -U postgres -c "CREATE DATABASE DATABASE_NAME; CREATE ROLE DATABASE_USER LOGIN PASSWORD 'DATABASE_PASSWORD'; GRANT ALL PRIVILEGES ON DATABASE DATABASE_NAME TO DATABASE_USER;"
      $ installdir/postgresql/bin/psql -U postgres -d database_name -c "CREATE EXTENSION hstore; CREATE EXTENSION pg_trgm;"
    
  • Create the Discourse multi-site config/multisite.yml configuration from the config/multisite.yml.production-sample sample file. Depending on your installation type, run the commands below:

    • Approach A (Bitnami installations using system packages):

        $ sudo cp installdir/discourse/config/multisite.yml.production-sample installdir/discourse/config/multisite.yml
      
    • Approach B (Self-contained Bitnami installations):

        $ sudo cp installdir/apps/discourse/htdocs/config/multisite.yml.production-sample installdir/apps/discourse/htdocs/config/multisite.yml
      
  • Edit the new file to use the database created previously. Replace the DATABASE_NAME, DATABASE_USER and DATABASE_PASSWORD placeholders with actual values, and the HOSTNAME placeholder with the host name for the new site.

      database_name:
        adapter: postgresql
        database: DATABASE_NAME
        username: DATABASE_USER
        password: "DATABASE_PASSWORD"
        host: installdir/postgresql
        pool: 25
        timeout: 5000
        db_id: 2    # ensure db_id is unique for each site
        ### If you change this setting you will need to
        ###   - restart sidekiq if you change this setting
        ###   - rebake all to posts using: `RAILS_ENV=production bundle exec rake posts:rebake`
        host_names:
          - HOSTNAME
    
  • For testing purposes, add the new hostname to the /etc/hosts file, as below:

      IP_ADDRESS HOSTNAME
    
  • Migrate the database. Depending on your installation type, run the commands below:

    • Approach A (Bitnami installations using system packages):

        $ cd installdir/discourse
        $ RAILS_ENV=production bundle exec rake multisite:migrate
      
    • Approach B (Self-contained Bitnami installations):

        $ cd installdir/apps/discourse/htdocs/
        $ RAILS_ENV=production bin/bundle exec bin/rake multisite:migrate
      
  • Create an administrative user:

      $ bin/rake admin:create RAILS_ENV='production' RAILS_DB=DATABASE_NAME
    

You should now be able to access your new site using the new domain name.

Last modification June 16, 2021