azurediscourse

Enable multi-site support

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

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.

      $ /opt/bitnami/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;"
      $ /opt/bitnami/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 /opt/bitnami/discourse/config/multisite.yml.production-sample /opt/bitnami/discourse/config/multisite.yml
      
    • Approach B (Self-contained Bitnami installations):

        $ sudo cp /opt/bitnami/apps/discourse/htdocs/config/multisite.yml.production-sample /opt/bitnami/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: /opt/bitnami/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 /opt/bitnami/discourse
        $ RAILS_ENV=production bundle exec rake multisite:migrate
      
    • Approach B (Self-contained Bitnami installations):

        $ cd /opt/bitnami/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