Despite having every intention of moving on from Discourse given the utter lack of current documentation that isn’t hyper-focused on CentOS/Nginx, an incredibly generous and patient individual at DigitalOcean responded to a thread I had created there and after some trial and error, helped put together a simple-to-follow tutorial for prospective Discourse users with the same circumstances as mine.
As a refresher, those circumstances are:
Installing Discourse on the same server as Apache | Using Ubuntu 18.04 | DigitalOcean
credit to Bobbyiliev @ DigitalOcean
https://www.digitalocean.com/community/questions/install-discourse-on-a-droplet-with-wordpress-served-by-apache (first answer)
Prerequisites
- To be on the safe side make sure to backup your Droplet, so that in case anything goes wrong, you could revert back to a working version
- SSH to your Droplet
- Apache installed, you can follow the steps on how to do that here:
Step 1 - Install Docker
To install Docker please follow the steps here:
Step 2 - Download Discourse
First, create a directory where you would store your Discourse files:
mkdir /var/discourse
After that clone the official Discourse Docker Image into /var/discourse
.
git clone https://github.com/discourse/discourse_docker.git /var/discourse
Step 3 - Configure Discourse to listen on port 8080
We will use the standalone.yml
template it includes all of the necessary services like PostgreSQL, Redis and etc.
You copy the sample file with the following command:
cp /var/discourse/samples/standalone.yml /var/discourse/containers/app.yml
After that edit the file with your favorite editor. Open the /var/discourse/containers/app.yml
and update and the ports on lines 23 and 24:
## which TCP/IP ports should this container expose?
expose:
- "8080:80" # fwd host port 8080 to container port 80 (http)
- "8443:443" # fwd host port 8443 to container port 443 (http)
Also if you do not yet have an SSL certificate make sure to comment line 16 out:
#- "templates/web.ssl.template.yml"
Just add the # symbol in front of the - "templates/web.ssl.template.yml
line otherwise Discourse would not start.
Step 4 - Setup Discourse
Change directory:
cd /var/discourse
Then, start Discourse (as this is the first time that you are starting the service it would bootstrap the application with the new changes that you have in your app.yml
file):
./discourse-setup
Note : Make sure to provide valid Mail server settings as otherwise, the setup might fail.
Step 5 - Setup Apache
In your /etc/apache2/sites-available/
create a new file called forum.example.com.conf
and add the following Vhost content:
<VirtualHost *:80>
ServerName forum.example.com
ServerAlias www.forum.example.com
<IfModule proxy_module>
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</IfModule>
</VirtualHost>
- Enable the Vhost with the following command:
a2ensite forum.example.com
- Enable Mod Proxy:
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_balancer
a2enmod lbmethod_byrequests
- Restart Apache:
systemctl restart apache2
And after that, you would be able to access Discourse directly via your domain name.
Note: 1 When installing Discourse, app.yml
may be overwritten and lines 16/17 (SSL) will be uncommented. You’ll need to comment those lines out again then rebuild the app (don’t forget to change directory): ./launcher rebuild app
Note 2: SSL is not enabled for Discourse with this guide. Unsurprisingly, it appears no documentation exists for enabling Let’s Encrypt SSL if you already have it enabled for Apache. If someone happens upon a solution for this, please reach out.