Discourse is a popular open-source forum software that is designed to be user-friendly and easy to set up. In this article, we will show you how to install Discourse on an Ubuntu 20.04 machine.
Before we begin, make sure that your Ubuntu 20.04 machine is up-to-date by running the following commands:
sudo apt update
sudo apt upgrade
Next, we will install some dependencies that are required for Discourse. Run the following command to install Git, PostgreSQL, and Nginx:
sudo apt install git postgresql nginx
Once the installation is complete, start the PostgreSQL service and enable it to start automatically on boot:
sudo systemctl start postgresql
sudo systemctl enable postgresql
Next, we will create a new PostgreSQL user and database for Discourse. Log in to the PostgreSQL shell using the following command:
sudo -u postgres psql
In the PostgreSQL shell, run the following commands to create a new user and database for Discourse:
CREATE USER discourseuser WITH PASSWORD 'password';
CREATE DATABASE discourse OWNER discourseuser;
Replace password
with a strong password for the Discourse database user.
Now, we will download and install Discourse. Clone the Discourse Git repository using the following command:
git clone <https://github.com/discourse/discourse.git>
This will download the latest version of Discourse to a new discourse
directory in the current directory.
Next, change to the discourse
directory and run the ./discourse-setup
script to set up Discourse:
cd discourse
./discourse-setup
This will start the Discourse setup wizard, where you will be prompted to enter the configuration details for your Discourse installation.
First, you will be asked to enter the hostname for your Discourse instance. Enter the fully-qualified domain name (FQDN) that you want to use for your Discourse forum (e.g. discourse.example.com
).
Next, you will be asked to enter the email address that will be used for the Discourse system account. This email address will be used to send notifications and alerts from Discourse.
Then, you will be asked to enter the database details that you created earlier. Enter the database name (discourse
), the database username (discourseuser
), and the database password (the password you chose earlier) when prompted.
Once the setup wizard is finished, it will generate a file named containers/app.yml
that contains the configuration for your Discourse instance. You can edit this file to customize your Discourse installation (e.g. to change the default SMTP settings for email notifications)
Paste the following contents into the file, replacing discourse.example.com
with the FQDN that you entered earlier:
Finally, we need to configure Nginx as a reverse proxy for Discourse. Create a new Nginx virtual host configuration file for Discourse using the following command:
sudo nano /etc/nginx/sites-available/discourse
Paste the following contents into the file, replacing discourse.example.com
with the FQDN that you entered earlier:
server {
listen 80;
server_name discourse.example.com;
location / {
proxy_pass <http://localhost:8080>;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Save the file and exit the editor. Then, enable the virtual host and restart Nginx for the changes to take effect:
sudo ln -s /etc/nginx/sites-available/discourse /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Now, open a web browser and navigate to the FQDN that you entered earlier (e.g. discourse.example.com
). You should see the Discourse login page, where you can create a new account and start using your Discourse forum.