I recently created this blog using Ghost 3.x. Whilst Ghost is an awesome publishing platform, it does not come with a built-in commenting system of it's own. Rather, it relies on you adding any number of external commenting systems, such as the hugely popular Disqus commenting system.
The problem with Disqus and other external commenting systems are they tend to bloat the post page, inject a ton of tracking scripts/cookies and bombard users with advertisements, especially the free versions.
After reading up on adding comments to ghost via the Ghost Forum, I settled on Commento, a small and privacy-focused open source solution. The minimum subscription is $5/month if you don't want to host the comments yourself, however, this is a bit high for a blog that I only pay $5/month for. Luckily they offer a self-hosted option. Here is how I got it setup.
Since I am running this blog on Digital Ocean I chose to install and run Commento from the same Droplet. You don't need to do this, but the smallest Droplet is sufficient to run Ghost and Commento side-by-side if your traffic isn't too high.
Prerequisites
- PostgreSQL: This is a requirement. This is a good guide for installation. Commento requires its own database. I created a system user named "commento" (
adduser commento
), matched it to a database role (createuser --interactive
, name it "commento") and a database of the same name (createdb commento
). When you are done make sure yousudo systemctl enable postgresql
to keep it running. - smtp: This is optional, but without it you wont be able to send activation or password reset emails. While its focused on gmail forwarding, you can use any smtp service such as mailgun for Commento. I highly recommend getting this setup.
- DNS: Commento needs its own (sub)domain to run on. I used commento.YOURDOMAIN.com, and pointed it to the same IP that Ghost is on.
Install Commento
At time of writing this, the binaries for Commento 1.8.0 were just released and made available. Previously the Commento 1.7.0 binariies were not available and had to be built from source. Now it is much easier to install.
Install from Binaries
# Switch to the root user
sudo su
# Download
wget https://dl.commento.io/release/commento-v1.8.0-linux-glibc-amd64.tar.gz
# Unpack
mkdir /usr/local/bin/commento
tar xvf commento-v1.8.0-linux-glibc-amd64.tar.gz -C /usr/local/bin/commento
Create SSL Cert
# Switch user
sudo -i -u ghost-mgr
# Navigate to ghost install root
cd /var/www/ghost
# Set Commento URL
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
ghost config url https://YOURBLOG.com
This will create certs with Lets Encrypt/acme.sh, as well as generate some NGINX conf files in /var/www/ghost/system/files
. The conf files point to Ghost though, and we need to reverse proxy them to the Commento server.
Update NGINX
We need to edit 3 files: the ssl and http conf files for Commento; and the ssl-params file used by NGINX.
We need to reverse proxy NGINX to the Commento server (that we will setup in the next step). In /var/www/ghost/system/files
update the commento*.conf
files. Their Location /
block should look like this
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name commento.YOURBLOG.com;
root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)
ssl_certificate /etc/letsencrypt/commento.YOURBLOG.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/commento.YOURBLOG.com/commento.YOURBLOG.com.key;
include /etc/nginx/snippets/ssl-params.conf;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8081;
}
location ~ /.well-known {
allow all;
}
client_max_body_size 50m;
}
server {
listen 80;
listen [::]:80;
server_name commento.YOURDOMAIN.com;
return 301 https://commento.YOURDOMAIN.com$request_uri;
}
Then, sudo nano /etc/nginx/snippets/ssl-params.conf
remove/comment out the following line:
# Find and comment out this line
add_header X-Content-Type-Options nosniff;
Note: this is necessary because of bad MIME type handling in Commento. Hopefully this will be fixed in the near-future.
Create the Commento Service
Create the following file: sudo nano /etc/systemd/system/commento.service
[Unit]
Description=Commento daemon service
After=network.target postgresql.service
[Service]
Type=simple
ExecStart=/usr/local/bin/commento/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
# Environment=COMMENTO_FORBID_NEW_OWNERS=true
# Uncomment after creating Akismet acc and grabbing API Key. Paste it below.
# Environment=COMMENTO_AKISMET_KEY=YOUR_API_KEY_HERE
[Install]
WantedBy=multi-user.target
Then run
sudo chmod u+x /etc/systemd/system/commento.service
sudo systemctl start commento
sudo systemctl enable commento
To get NGINX routing to Commento you will need to restart it.
sudo nginx -s reload
Finally check that the commento service is running
sudo lsof -i -n|grep LISTEN|grep commento
Register Domain in Commento
Commento should be running now. You need to complete the domain setup in the Commento dashboard (the one running on your server, not the cloud one).
Now you need to secure the installation to stop anyone adding themselves as an owner:
sudo nano /etc/systemd/system/commento.service
Uncomment the following line
Environment=COMMENTO_FORBID_NEW_OWNERS=true
Finally, restart the commento service
sudo systemctl enable --now commento
Add Commento code to Ghost Template
Once your domain is registered in the dashboard a snippet is provided under the installation section. It looks like this
<div id="commento"></div>
<script src="https://commento.YOURBLOG.com/js/commento.js"></script>
You will need to add this to /var/www/ghost/content/themes/casper/post.hbs
. The section is near the bottom, in a commented out block. Uncomment the container and replace the contents with the above snippet.
To get Ghost to compile and use the new template, restart Ghost
# Switch to the commento user
sudo -i -u ghost-mgr
# Move to Ghost root
cd /var/www/ghost
#Restart
ghost restart
You should be all set. Comments should start showing up in your posts.