vmware-marketplacediscourse

Enable multi-site support

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:

      $ sudo cp /opt/bitnami/discourse/config/multisite.yml.production-sample /opt/bitnami/discourse/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:

      $ cd /opt/bitnami/discourse
      $ RAILS_ENV=production bundle exec 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 February 9, 2023