For years now, I've self-hosted Ghost on DigitalOcean to run this blog. I do not regret it; Ghost is an absolute pleasure to use.
However, it lacks some key features for a publishing platform, like built-in comments. Three major releases in, Ghost still doesn't ship with comments. Instead, in an attempt to remain lean, it expects us to use external solutions.
At first, I tried Disqus to host my comments–which was slow, ugly, and fickle. I then switched to utteranc.es, which certainly looked better, but now users had to login with Github first. This was still an improvement over Disqus, so I kept it for the moment.
Why Commento is the Chosen One
I was swayed to choose Commento because:
- It supports anonymous comments
- It supports anonymous comments
- It supports anonymous comments (I'll stop now but this really does make commenting painless)
- It is the most beautiful/cleanest solution by far
- The self-hosted version is free (but takes a bit more time to set up)
- It's feather light, therefore also bloody fast
- You can easily import all your Disqus comments as well as export from Commento if you decide to move
- It's painless to configure spam detection thanks to the Akismet integration
- You can even set up login with third-party sites (like Twitter) [that we're not doing in this post]
Without further ado, here's my day-long tinkering compressed into a concise guide.
This post will guide you through the following:
- Install PostGreSQL & create your pSQL user+database for Commento
- Create a subdomain, generate its SSL certificate, and point it to Commento
- Download Commento
- Create a service config file for Commento, and get systemd to keep it running
- Configure Commento and add its script code into your theme
- Add and configure Mailgun for sending verification/notification emails [Optional but highly recommended]
- Configure Akismet for filtering spam comments [Optional but recommended]
Remember, we're assuming that you're using nginx. Let's jump into it!
1) Install PostGreSQL and create DB
Commento uses PostGreSQL for storing comments. Install it using the following:
sudo apt update sudo apt install postgresql postgresql-contrib
At this point we're going to create a system user named
commento, match it to a new database role (
commento), then create a database named
# Keep postgresql running sudo systemctl enable postgresql adduser commento # Switch to newly created user sudo -i -u commento # Create role called commento. When prompted for superuser, say yes. createuser --interactive createdb commento
2) Download Commento
Stay logged in as the
commento user. Find the latest binary here. Right click the topmost Linux text and copy the link, then paste it below in the
wget command to download the file:
# Replace the link you found on the releases page here wget LATEST_BINARY_LINK_HERE # Unpack tar file into newly created commento-server folder mkdir commento-server tar xvf BINARY_FILENAME_HERE -C commento-server
3) Create Subdomain and SSL Certs
⚠ Head to your DNS management panel and create a new subdomain, which we'll use to access the Commento dashboard etc. Point it to the same IP that Ghost uses. I'm using the
This is a bit of a hack, but we're going to leverage acme.sh (that Ghost uses under the hood) to generate the SSL certs and config files.
# Switch to ghost-mgr user since we'll be executing Ghost commands. Exit to root first though (using exit command) sudo -i -u ghost-mgr # Navigate to ghost install root cd /var/www/ghost # Temporarily set Ghost site URL to Commento subdomain ghost config url https://commento.YOURBLOG.com # Get Ghost-CLI to generate an SSL setup for you: ghost setup nginx ssl # Switch back to your Blog URL ghost config url https://YOURBLOG.com
The newly generated nginx config files need to get nginx to reverse proxy to Commento, so in
/var/www/ghost/system/files/, update the
commento*.conf files so their location block looks like this:
Save and exit.
4) Create a systemd service file for Commento
Create the service file using
sudo nano /etc/systemd/system/commento.service
Paste the following into it:
[Unit] Description=Commento daemon service After=network.target postgresql.service [Service] Type=simple ExecStart=/home/commento/commento-server/commento Environment=COMMENTO_ORIGIN=https://commento.YOURBLOG.com Environment=COMMENTO_PORT=8081 Environment=COMMENTO_POSTGRES=postgres://commento:[email protected]:5432/commento?sslmode=disable # Uncomment after setting up SMTP as specified below. # Environment=COMMENTO_SMTP_HOST=smtp.mailgun.org # Environment=COMMENTO_SMTP_USERNAME=YOUR_SMTP_USERNAME_HERE # Environment=COMMENTO_SMTP_PASSWORD=YOUR_SMTP_PASSWORD_HERE # Environment=COMMENTO_SMTP_PORT=587 # [email protected] # Uncomment after creating your first user on commento.YOURBLOG.com # COMMENTO_FORBID_NEW_OWNERS=true # Uncomment after creating Akismet acc and grabbing API Key. Paste it below. # COMMENTO_AKISMET_KEY=YOUR_API_KEY_HERE [Install] WantedBy=multi-user.target
ExecStart parameter set to the location where we extracted Commento to. The
COMMENTO_ORIGIN parameter is set to the subdomain where we'll be accessing Commento. More info here.
We've commented out the SMTP parameters because when I tried it the first time with those enabled (even with Mailgun configured), I never got the verification email, and thus couldn't sign into the dashboard.
Save and exit. Now let's set the right permissions(read+write) for this file and get the service running
sudo chmod 644 /etc/systemd/system/commento.service sudo systemctl start commento sudo systemctl enable commento
5) Configure Commento
commento.YOURBLOG.com and register a new user.
Immediately uncomment the
COMMENTO_FORBID_NEW_OWNERS parameter in our service file above and re-run our service using
sudo systemctl enable --now commento
Once done, sign into Commento using those same credentials from above. Click on
Add Domain button in the top left.
Now, click on the domain you just added in the sidebar and you will be able to enable/disable anonymous commenting, import your old Disqus comments, and more. If you want to configure Akismet later, make sure
Automatic spam filtering is enabled.
Once done, hit
Save Changes. Now head to the
Installation Guide tab and copy the HTML snipper, which should look like this:
<div id="commento"></div> <script src="https://commento.YOURBLOG.com/js/commento.js"></script>
Now, download and unzip your Ghost theme, run
yarn install in the theme folder followed by
yarn dev. Open the
post.hbs file and find the comment section code. Paste in the snippet, so it looks something like this:
Save and exit. Hit Ctrl+C to end the yarn dev, then run
If you look inside the theme/dist folder, you should see the zipped theme. Upload this back to your blog on your Ghost admin panel and set as default.
You should now see Commento on your posts. Keep going to complete this setup.
Highly recommended: Add Mailgun for verification and email notifications
I suggest you use Mailgun for sending those SMTP emails, so that you can be notified when new comments are added.
Sign up on Mailgun for a free account. You'll be asked to enter details for a credit card, but you won't be charged. Once done, head to Sendings > Domains.
Click on Add New Domain. You will have to choose a subdomain from where Mailgun will be sending emails. Once done, you'll see various DNS records that you'll need to add. After you do that, click
Verify DNS. If successful, you can head onto Sending > Domain Settings and click SMTP credentials.
You'll find every value you need here (including the SMTP email and password), which you have to replace back into our initial Commento service file. Uncomment all the SMTP lines.
Don't forget to run
sudo systemctl enable --now commento after you make your changes. That's it, you should be able to get notification emails now!
Optional: Add Akismet Protection to prevent spam comments
Go to Akismet and get yourself an account (It's free if your site is non-commercial).
As soon as you're done, you should see the API key. Copy it, we're going to need it.
You can now re-edit
/etc/systemd/system/commento.service and uncomment the
COMMENTO_AKISMET_KEY parameter. Replace YOUR_API_KEY with your actual API key.
Once done, run
sudo systemctl enable --now commento to update your changes.
Aaand that's it! If you reached here, you should have gotten Commento up and running. If you want to test it out, just scroll down. Hope I helped!
Bibiliography: This article was largely made possible through two awesome guides, https://blog.kye.dev/self-hosting-commento/ and https://techroads.org/building-a-self-hosted-commento-system-for-embedding-comments-with-docker-and-traefik/. I found errors (such as the contents of the service file) and outdated info in 1) whereas 2) was slightly unclear for beginners and made use of Docker, so I thought I'd write down a guide that provided greater understanding and less head-scratching.