Installing Ghost from scratch
I've done fresh installs of Ghost a few times and I thought I'd document it all here, to make it simpler for myself and others who may find this helpful. Here we go.
Includes affiliate links.
What is a "Ghost website"?
A ghost website contains the following:
- Domain - an address to redirect your website to.
- Server - a computer to host your website on.
- Mail functionality - a way to send emails to subscribers.
Main Setup
Buy a domain
Unintuitively, the first step is to buy a domain. You will be asked by . I like to buy mine from Cloudflare Registrar - they tend to be the cheapest ones out there.
Obtain a server
I like to just use DigitalOcean's Ghost droplet image. They have a one-click setup for Ghost, which has been very useful. However, all you really need is some space on a computer that can host a website.
If your server lives on the web, you can use any terminal or command prompt to log in to it. I like to use Tabby however to manage my servers.
Install Ghost
If you are using DigitalOcean, on your first login, the droplet will automatically start the installation.
Otherwise, you can follow their official installation guide here. On first access into the DigitalOcean droplet, all the software will get configured.
Set up MySQL for production
There is a message by DigitalOcean saying you should update your MySQL configuration. So you should do so:
- Get your password from the login screen
- Run
mysql_secure_installation
- Follow the on-screen guide
Set up emails
Set up Mailgun
- Sign up for mailgun on the free trial.
- Follow the steps to set up your mailgun account. Enter your credit card details and select "Foundation Trial" for now.
- Go to account plans. Next to the "upgrade" button, click the gear button and select "Unsubscribe". You'll be on the Flex Plan, which is more relevant for us (and free too).
- Add your domain to mailgun by following the official guide or instructions in your account. Click "Verify DNS Settings" to make sure changes are received by Mailgun.
- Under receiving routes, set it to send to your support email address.
- Go to Sending > Domain Settings > SMTP Credentials. Click "Reset Password" and copy the value there. This will be important later for SMTP setup, which is required for verification and admin emails.
Set up on server (SMTP)
- Go into your Ghost folder. This is typically
/var/www/ghost
- In
config.production.json
, change the mailing settings to mailgun:
"mail": {
"transport": "SMTP",
"options": {
"service": "Mailgun",
"host": "smtp.mailgun.org",
"port": 587,
"secureConnection": false,
"auth": {
"user": YOUR_SMTP_USER,
"pass": YOUR_PASSWORD
}
}
},
- Run the command
ghost restart
as your ghost user.
Set up Ghost
- Go into Settings > Newsletters, and then add in your mailgun details following the instructions.
- Remember to scroll up and click "Save".
- Under Settings > Membership > Customise Portal > Account Page Settings, change the email you want people to reply to your newsletters to.
Monetisation
If you want to monetise your blog, there are additional steps to take.
Set up Stripe
If you want to collect payments for your website, you should have Stripe set up as well, and linked to Ghost.
Create Stripe account
Fill in your necessary details and set up payment methods.
Set up on Ghost
Go to Settings > Membership > Click "Connect with Stripe".
Set up Google Ads (or other ads)
Apply for Google Adsense
There are some criteria for that, such as having enough content on your blog, cookie consent and so on.
Add ads.txt to Ghost
This is a bit tricky:
- Download your theme in a zip folder (under Settings > Design > Advanced > "...")
- Extract all the files in the zip folder.
- Add a file called ads.txt with the required info into the main folder.
- Zip the theme back up.
- Upload the theme zipped folder in "Upload Theme" under Settings > Design
- Switch to the uploaded theme.
Security
Add swap space
To do so, follow the below tutorial.
Cookie Consent
You can add either Osano or CookieYes, and follow their instructions from there. To add the code, you can follow this tutorial to inject code into your site:
Set up Cloudflare
It's free and can help you:
- Protect your website from attacks
- Keep your original server IP address safe
You can follow the instructions in "Add Zone" in cloudflare to set this up.
Set up www and non-www redirects
You can do this so that www.mysite.com leads to mysite.com automatically.
On Digital Ocean
- Add an 'A' record for the www. version (see tutorial)
After that, you will configure it differently based on whether you have set up cloudflare:
On server (if no cloudflare)
- Switch to the ghost manager:
sudo -i -u ghost-mgr
- Use this Ghost tutorial to configure https for the secondary site
- Replace :
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:2368;
}
with:
location / {
return 301 https://yoursite.com$request_uri;
}
- Do this for both https and non-https configurations.
In cloudflare (if using cloudflare)
Follow this tutorial to see the configurations for bulk redirects.
Sometimes I get a too many redirects error. Check out this page to solve it:
After applying bulk re-routing, I changed the encryption mode to Full, and on "Edge Certificates" I turned on everything except for Total TLS, HTTP Strict Transport Security (HSTS) and Certificate Transparency Monitoring.
Restart Ghost
Run ghost restart
to check if everything is set up correctly.
Set up Github
This is to ensure you have a copy of the code running your website.
- Set up a repository remotely.
- Set up locally:
git init --initial-branch=main
git remote add origin <blog-url>
git branch --set-upstream-to=origin/main main
Set up anything else as required, such as usernames and so on.