- Droplet Setup
- Install Prerequisites
- Install Ghost
- MySQL 8 Compatibility
On my journey to find the blogging platform that I wanted to use, Ghost ended up being one of the top candidates I was considering. It’s very simple, lightweight, and easy to use. Ghost comes with easy to use social integrations, RSS support, easy SEO optimizations, beautiful themes to pick from, and easy customization! After hearing this, I decided to install it and give it a whirl to see what all the fuss was about.
Now, before we can get to all the fun, we have to find a server that you can install Ghost on. This can be a physical server or an VPS hosted in the cloud. Personally, I went with the second option. I like to use either Linode or DigitalOcean (Full disclosure, these are referral links, and at the time of writing if you use the Digital Ocean link, you get $100 of credit to use for the first 60 days). For this test I am going to use Digital Ocean.
To set up a droplet (VPS), log into your account and click on Create in the top right hand corner.
You will be brought to the droplet creation page where you can specify the settings of your vm. For this example, we want to pick Ubunutu: 20.04 (LTS) x64 as the image, Standard for the plan, and the $5/month option.
After that you’ll want to pick the data center that is closest to you (or your audience) for the best performance.
Next, you will want to set up authentication. It is recommended that you use SSH keys for authentication. If you don’t already have an SSH key ready, or haven’t added it to DigitalOcean, click on New SSH Key. This will give you a popup with instructions on how to generate/add an SSH key to DigitalOcean for authentication.
After all the settings look correct, click on Create Droplet and you will have completed creating your droplet!
I would recommend getting your domain name and setting up DNS settings before continuing with the rest of the guide as it takes some time for DNS settings to propagate throughout the internet. You need the DNS records to be live when setting up Ghost with SSL/TLS.
The first step to setting up your domain name to work with the droplet you just created is to point the DNS servers to Digital Ocean DNS servers in the control panel of your domain name registrar. You’ll want to add these three addresses as your DNS servers:
ns1.digitalocean.com ns2.digitalocean.com ns3.digitalocean.com
After everything is set up on the end of the registrar, it’s time to set things up on DigitalOcean. Click on the Networking tab on the left column, and type in your domain name under Add a domain. After you click Add Domain your domain will appear under the Domains table.
Now that we have added the domain, we’ll need to set up a DNS record to tell computers what server the name points to. Click on More > Manage Domain, which is on the right side of the domain name entry in the Domains table. We want to create an A record, so we don’t have to click on any of the name record options. Under Hostname type in @ to use the root domain or something else to use a sub-domain (@ will use yourdomain.com, sub will use sub.yourdomain.com). Then you’ll want to select the droplet you just created in the next box and then hit Create Record.
There are a few housekeeping things we need to do before installing Ghost. First, we have to connect to the droplet we just set up. If you’re using Linux or macOS, you can just open a terminal. If you’re using windows, you can use Powersh. Type in the following to connect to your server:
You can find the IP for your droplet on the home page of your DigitalOcean accounts next to the name of your droplet. After running this command, you might be prompted to put in a password. This is the password you entered when you generated your SSH key. Afterwards, if everything goes well, you should be connected to your droplet as the root user!
Now let’s make sure everything is up to date by running this command:
If it says that there are packages to be upgraded, run the following:
After everything finishes updating, reboot the server:
This will kick you out of your SSH session, so wait a minute or so and then reconnect to the server with the command from earlier. After reconnecting, let’s add a user so that we don’t have to keep using the root user to do things:
Remember to replace username with the username you want to use on the server. Next, we’ll want to grant the user we just created admin permissions so that we can use this user to do things on the server:
usermod -aG sudo username
Now, we’ll set up a basic firewall to protect the server. We’ll allow the ports we need to use such as the HTTP, HTTPS, SSH ports by running the following commands:
ufw allow OpenSSH ufw allow http ufw allow https ufw enable
Lastly, we’ll want to make sure that we can connect to the server using the user we just created through SSH:
rsync --archive --chown=username:username ~/.ssh /home/username
This command copies the authorized ssh keys to the new user you just created. Now we can exit this SSH session:
and connect to the server using the user that was just created!
I promise we’re almost done installing everything that isn’t Ghost. We just need to install a few of the things that Ghost needs to run, such as NGINX, MySQL, Node.js.
To install NGINX, run this command:
sudo apt install nginx
Now we’ll install the latest version of Node 12, since this is the current long term support version and also the version that Ghost officially supports.
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E sh -
This adds the correct repository so that we can install the version we want. Now we’ll actually install it.
sudo apt update sudo apt install nodejs
Now let’s double check the version of Node installed:
Make sure this returns
v12.x.x with x being numbers. The last thing we need to install before ghost is MySQL. The official Ghost documentation says they only support MySQL 5.5, 5.6, or 5.7, but I did manage to get it to work with MySQL 8. By default DigitalOcean sets up your repositories to use MySQL 5.7, so you don’t have to do anything extra if you are using DigitalOcean.
sudo apt install mysql-server
After installing, you can check your version of MySQL:
At the top the MySQL prompt it’ll tell you the version of MySQL being run. If the version of MySQL is 8 or above, you’ll have to pay attention and alter a few things while installing.
While we’re in the MySQL console, let’s change the root password so that Ghost can login:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Replace password with the actual password you want to use. After you set the password, we can exit the MySQL console:
Finally! We’re getting to the good part. For the most part, Ghost makes the installation process very easy:
sudo npm install ghost-cli@latest -g
Now, go to/create the folder you want to install Ghost in and install ghost:
If you run into and error with folder permissions, make sure the permissions are correct:
sudo chown username:username pathToDirectory sudo chmod 775 pathToDirectory
After Ghost installs properly it’ll ask you a few questions to finalize the install.
Enter your blog URL: This should be the domain name you purchased (yourdomain.com)
Enter your MySQL hostname: Just hit enter to use the default localhost.
Enter your MySQL username: Enter root.
Enter your MySQL password: Enter the password you set up earlier.
Enter your Ghost database name: Hit enter to use the default ghost_prod.
Do you wish to set up a ghost MySQL user? Enter Y unless you have MySQL 8+. If you have MySQL 8+, then enter n.
Do you wish to set up NGINX? Enter y.
Do you wish to set up SSL? Enter y.
Enter your email for SSL: Put your email in.
Do you wish to set up systemd? Enter y.
Do you wish to start Ghost? Enter y.
Although there’s a little more work to do, you should be able to navigate to your domain and see an installed instance of Ghost!
MySQL 8 Compatibility
To get ghost to work with MySQL 8+ using root, let’s create another user manually:
sudo mysql -p
Once you’re in the MySQL command line, let’s create a user:
CREATE USER 'ghost-db'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Remember to replace password with the password you want to use. Now we want to grant permissions for this use to modify the ghost_prod database:
GRANT ALL PRIVILEGES ON ghost_prod.* TO 'ghost-db'@'localhost'; FLUSH PRIVILEGES; exit
Now that the user is set up, let’s change the user in Ghost settings which is located in the config.production.json file in your the directory Ghost is installed in, and change the database user and password to the user you just created. Here’s how I do it:
cd pathToDirectory/ vim config.production.json
Located the lines you want to edit. Hit
i to started editing. Then type
:wq to save and exit vim. Now all we have to do is restart ghost:
sudo systemctl restart ghost_yourdomain-com.service
If you can’t find the service, just type in
sudo systemctl restart ghost and hit tab. It should autocomplete for you.
Finally you can go to
https://yourdomain.com/ghost/ to start configuring your newly set up blog!
- Creating a droplet (https://www.digitalocean.com/docs/droplets/how-to/create/)
- Setting Up DNS for various domain name providers (https://www.digitalocean.com/community/tutorials/how-to-point-to-digitalocean-nameservers-from-common-domain-registrars)
- Initial server setup. (https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04)
- Ghost install. (https://ghost.org/docs/install/ubuntu/)
- MySQL 8+ help. (https://github.com/TryGhost/Ghost-CLI/issues/833)