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.
- 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 you
sudo systemctl enable postgresqlto 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.
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.
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
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
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
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.