generaldiscourse

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;"
      $ /opt/bitnami/postgresql/bin/psql -U postgres -c "CREATE USER DATABASE_USER; ALTER ROLE DATABASE_USER WITH PASSWORD 'DATABASE_PASSWORD'; GRANT ALL PRIVILEGES ON DATABASE DATABASE_NAME TO DATABASE_USER"
      $ /opt/bitnami/postgresql/bin/psql -U postgres -c "ALTER DATABASE DATABASE_NAME OWNER TO DATABASE_USER;"
      $ /opt/bitnami/postgresql/bin/psql -U postgres -d database_name -c "CREATE EXTENSION HSTORE; CREATE EXTENSION pg_trgm;"
    
  • Copy the config/multisite.yml.production-sample file:

      $ sudo cp /opt/bitnami/apps/discourse/htdocs/config/multisite.yml.production-sample /opt/bitnami/apps/discourse/htdocs/config/multisite.yml
    
  • Edit the 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/apps/discourse/htdocs
      $ bin/bundle exec bin/rake multisite:migrate RAILS_ENV='production'
    
  • 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 April 8, 2020