Setting up 2 Ghost blogs on 1 server
I moved my domain from the .co.uk
to .dev
and at the same time I wanted to set up a blog for our farm.
I really like the Ghost blogging platform, so I wanted to stay with them, but I didn't want to pay for 2 servers, so I wanted to see if it was possible to host 2 ghost blogs on 1 server, without a lot of hassle.
The good news is that the Ghost CLI handles it all really well.
For each installation, Ghost will set up its own database user, its own database, its own Nginx configs, its own SSL certificates and even its own ghost systemctl runner (as far as I can tell).
The only thing you need to do to make it happen is give each ghost instance its own folder to live in and the Ghost CLI takes care of the rest.
If you know how to do the rest, then you can stop reading here.
But if you are not 100% sure on how to set up a ghost blog, I will go through the steps to do so.
Ghost Blog Setup
These are the 2 articles that I used to get an idea of how to install a single ghost blog.
https://www.linuxbabe.com/ubuntu/install-ghost-blog-ubuntu
https://ghost.org/docs/install/ubuntu/
I ended up doing a combination of both of these, so my walkthrough is a little different.
Update Ubuntu
I started with a server with ubuntu installed, so once I had logged into the server, the first thing I did was update the packages.
sudo apt update;sudo apt upgrade
# chose to keep the grub file when there was a new version
Install NodeJs
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install nodejs
node -v
# v10.18.1
npm -v
# 6.13.4
Install MySQL
sudo apt-get install mysql-server
Secure Mysql.
mysql_secure_installation
This script walks your through a few options that will secure MySQL.
Make sure that you set a root password in this step as it will be needed for Ghost-CLI.
Enable MySQL on startup.
sudo systemctl enable mysql
Install Nginx Web Server
Ghost needs a web server to handle incoming web requests and passing them to the running ghost instances. In our case, we will use Nginx.
sudo apt install nginx
If you are using the UFW firewall, then you also need to open port 80 and 443.
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Create an A Record For Your Blog Domain Name
Before installing Ghost, it’s recommended that you create the DNS A record
for your blog domain name. The A record points your domain name to the IP address of your Ubuntu server.
I bought my 2 new domain names from NameCheap and used their DNS to create A records
pointing to the server IP address for @
and www
.
Note: This step is important, I messed this step up and pointed the A record
to the wrong ip for the first one I set up. I ended up having to uninstall it and delete all the things it had done and run it again on a clean folder to reinstall it.
Install Ghost
Install Ghost-CLI.
sudo npm install ghost-cli@latest -g
This installs the Ghost-CLI globally so that it can be used from anywhere on the server.
Installing a Ghost website
This is the part that needs to be repeated for each blog that you want to install on your server.
You will just need to make sure that they each have their own installation folder.
eg:
/var/www/firstblog/
/var/www/secondblog/
To create a directory do the following:
sudo mkdir -p /var/www/firstblog/
You then need to give your user special permissions for this new folder. Replace youruser
with your actual username on the server.
sudo setfacl -R -m u:youruser:rwx /var/www/firstblog/
sudo chown youruser: /var/www/firstblog
sudo chmod 775 /var/www/firstblog
Next navigate to this new directory
cd /var/www/firstblog/
Then, you run Ghost-CLI and let it do the rest.
ghost install
It will ask you questions along the way.
When it asks for the website url, according to one of the guides I was following, if you give it to them with the https
on the front, like https://firstblog.com
then Ghost will ask you about setting up the SSL for you and then do it all for you if you say yes.
Other things that it asks you are for the MySQL server location, which if you have been following this guide will be localhost
and then you will need to give it root
as the MySQL user and then give it the root password you set earlier.
I just said yes to everything else and when it was done, the site was all set up for me and running, ready for me to login and start adding content.
Again, if you create another directory with permissions and do the ghost install
command again, it will create a second, completely separate instance that will run separately alongside your other instance.