Install Plugins in Discourse

:warning: This guide assumes that you have a self-hosted standard installation. We only support the standard method of install here, so these instructions assume you have a standard install.

:warning: This guide only applies to self-hosted Discourse instances. If you are using a managed hosting service, the available plugins are controlled by your hosting provider. For example, on our hosting these specific plugins are available by hosting tier.

In this tutorial, we’ll install the Discourse Spoiler Alert plugin.

This tutorial requires an understanding of how to use GitHub repos, specifically, how to get or copy the git clone URL and how to edit YAML (*.yml) files via the terminal using nano, specifically how to save and exit on nano. YAML files strongly follow indentations, so be sure to respect these as you copy and paste and edit the necessary *.yml for your Discourse instance.

  • Copy the plugin’s GitHub git clone url.

  • Access your container’s app.yml file (present in /var/discourse/containers/)

    cd /var/discourse
    nano containers/app.yml
    
  • Add the plugin’s repository URL to your container’s app.yml file:

    hooks:
      after_code:
        - exec:
            cd: $home/plugins
            cmd:
              - sudo -E -u discourse git clone https://github.com/discourse/docker_manager.git
              - sudo -E -u discourse git clone https://github.com/discourse/discourse-spoiler-alert.git
    

    Add the plugin’s git clone url just below the line containing git clone https://github.com/discourse/docker_manager.git)

    Follow the existing format of the docker_manager.git line; if it does not contain sudo -E -u discourse then insert - git clone https://github.com/discourse/discourse-spoiler-alert.git.

  • Rebuild the container:

    cd /var/discourse
    ./launcher rebuild app
    

    That’s it, you’ve successfully installed the Discourse Spoiler Alert plugin on your Discourse instance!


If your plugin is hosted in a private repository

You must use an OAuth token:

With the OAuth token, you can install your plugin in the same way as a public repo, and you don’t need to create a SSH key.

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
              - sudo -E -u discourse git clone https://<token>@github.com/owner/repo.git

We strongly advise you to use OAuth tokens for plugins in private repositories. However, if you cannot, see below.

SSH Key Private Install Steps
run:
  - exec: echo "Beginning of custom commands"
  
  - exec: cd /var/www/discourse && sudo -u discourse bundle install --deployment --without test --without development
  - exec: echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /user/.ssh/config
  - file:
      path: /user/.ssh/id_rsa
      chmod: 600
      contents: |
        -----BEGIN RSA PRIVATE KEY-----
        MIIEogIBAAKCAQEArCQG213utzqE5YVjTVF5exGRCkE9OuM7LCp/FOuPdoHrFUXk
           .... etc ....
        -----END RSA PRIVATE KEY-----
  - file:
      path: /user/.ssh/id_rsa.pub
      chmod: 600
      contents: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tj .... etc .... user@discourse
  - exec: cd $home/plugins && git clone git@github.com:SecretOrg/secret-plugin.git
  - exec: cd $home && sudo -E -u discourse bundle exec rake db:migrate
  - exec: cd $home && rm -fr tmp/cache
  - exec: cd $home &&  sudo -E -u discourse bundle exec rake assets:precompile
  - exec: rm /user/.ssh/id_rsa
  - exec: rm /user/.ssh/id_rsa.pub

  - exec: echo "End of custom commands"
  • Rebuild the container:
cd /var/discourse
./launcher rebuild app

Your private plugin should be installed on your Discourse instance.

How to uninstall a plugin

To remove a plugin, simply remove the - git clone https://github.com/... line from your app.yml file and rebuild your site via

cd /var/discourse
./launcher rebuild app
152 Likes

after install plugin, i must rebuild the project???

1 Like

That’s right. You would need to add the plugin to your app.yml and then ./launcher rebuild app :+1:

New to Discourse and strangely can’t find much info on installing plugins. Here’s some info I’d like:

Where can we find plugins to install?
Is there some kind of search feature, like WordPress?
Is there some kind of one-click installation of plugins (again, like WP)?
Is there a private marketplace for plugins?

Discourse seems like a cool platform but not exactly user friendly… like WordPress. Sorry but just being honest.

The Category plugin :wink:

(Note many Discourse plugins are also tagged accordingly on GitHub).

Well you can search within that Category using meta’s advanced search feature (common to all Discourse instances).

Normally, you must add them to app.yml as directed and rebuild.

Note there are also less invasive theme-component you can install without rebuilding.

No. Though at least one pavilion plugin is Subscription based.

If a plugin doesn’t exist that you need help building, you can post in marketplace, but there are usually many different ways to solve a problem, so be sure to ask the community first to see if there is solution already in existence.

1 Like

Not as part of Discourse and not for free, but https://dashboard.literatecomputing.com/ will allow you to select plugins from a searchable pull-down menu and then click a button to add them to your app.yml (or web_only.yml if you have a 2-container installation) and rebuild (or bootstrap, destroy, start for 2-container).

The dashboard uses Ansible to apply the changes, so it works with any standard install, so you can switch the dashboard or the command line as you see fit.

2 Likes