How to self-host Commento on your server
Note: This post assumes that you are running an Ubuntu machine (VPS) and use Nginx to handle the reverse proxy to your site.
Why I make this?
Sometimes websites and blogs need comments. And sometimes you don’t want to use Disqus because it is bloated and tracks your users. So you use Commento because it is an open source commenting service that is privacy first and lightweight.
Commento++ is a fork that I highly recommend. It has some nifty features like commenting with a name instead of logging in.1
Here’s how to self-host Commento (or Commento++) it on your server.
The Structure
There are five main steps to this –
- Setting up PostgreSQL
- Installing Commento or Commento++
- Configuring DNS, Nginx and Let’s Encrypt
- Running Commento as a system service
- Setting up Commento admin dashboard
0. Housekeeping
First, some cleaning up –
sudo apt update
1. Setting up PostgreSQL
Install the necessary packages –
sudo apt install postgresql postgresql-contrib
Start the postgresql service, check if it’s working correctly and make it run on boot by default –
|
|
Now let’s set up the user and database –
|
|
Excellent. Your PostgreSQL database and user is now set up and receiving on the default port (5432).
2. Installing Commento
First we create a new user on our machine. You could do this within your normal user (don’t use root please) but that makes cleaning up difficult. With a separate user you can just use sudo deluser --remove-home commento
and get rid of most things.
Anyway, the user –
|
|
Time to install Commento –
|
|
Congratulations. You have installed Commento. But it won’t work yet.
We need to define the environment variables first –
|
|
Copy the following configuration –
|
|
One last step –
|
|
3. Configuring DNS, Nginx and Let’s Encrypt
Find out how you can create a new A record on your domain name provider. It should usually be under the DNS settings somewhere. When you do figure it out, we will create a new subdomain on your site like so –
Create a new A record with the following properties –
- Name: commento
- Type: A
- TTL: 1hr
- IP: <Your VPS’ IP Address>
Now we tell Nginx to direct traffic –
|
|
|
|
Important: We will use port 8081 for Commento. You can change this if you like but only do it if you know what you are doing. If you do change the port, remember to change the port value in the nginx server configuration above and in the commento.env
file defined before.
Good, now we create a symlink to make sure this works –
sudo ln -s /etc/nginx/sites-available/commento.<YOUR DOMAIN NAME> /etc/nginx/sites-enabled/commento.<YOUR DOMAIN NAME>
Just a quick test to ensure that nothing is broken –
|
|
Brilliant. Time to get that HTTPS certificate.
If you don’t already use Let’s Encrypt, you should. A quick search online should help you find a tutorial.
When you’ve got certbot on your system, run –
|
|
Well done. Time to breathe life into Commento.
4. Running Commento as a system service
Create a new systemd service file –
sudo nano /etc/systemd/system/commento.service
Copy the following configuration –
|
|
Tell Ubuntu to run Commento –
|
|
Now head over to commento.<YOUR DOMAIN NAME>
and you should see the login page.
5. Setting up Commento admin dashboard
- Go to
commento.<YOUR DOMAIN NAME>
and create a new user by signing up. Don’t lose these credentials. - Add your domain.
- Click through the tabs. Set the relevant settings as you like.
- Go to the installation guide tab and copy the HTML code.
- Embed this code wherever you want the comment section to be in your site.
Great success. You have done it.
Appendix
- If for some reason you would like to investigate the Postgres DB using a GUI you should follow the steps in this guide. Basically, open the traffic to the Postgres server on your VPS to the world, then connect to it using a GUI tool like Table Plus.
- Commento is highly customisable. Read this page on the official docs. If you want to make some modification that don’t fall in this doc, a nifty way to do it is to write overriding CSS / JS code. I do that on my website to mask the login feature entirely and it works fairly well.
-
Side note: I use this feature as a proxy for SSO on one of my projects ↩︎