How to create a Ghost Blog on DigitalOcean: A Technical Guide

How to create a Ghost Blog on DigitalOcean: A Technical Guide

Ghost is a popular open-source blogging platform known for its simplicity and performance. This guide will walk you through the process of setting up a Ghost blog on DigitalOcean, a cloud infrastructure provider. We'll cover everything from creating a droplet to configuring Ghost on your droplet.

Step 1: Create a DigitalOcean Droplet

  1. Log in to your DigitalOcean account.
  2. Head over to the official Ghost app in the Digital Ocean marketplace.
  3. Click on the “Create Ghost Droplet” button.
  4. Choose a datacenter region close to your target audience.
  5. Select a CPU plan (minimum 1GB RAM recommended).
  6. Add SSH keys for secure access.
  7. All other options for the Droplet can be selected based on preference.
  8. Click "Create Droplet" to initialize your server.

Step 2: Connect to Your Droplet

Use SSH to connect to your droplet:

ssh root@your_droplet_ip

Step 3: Update and Upgrade the System

sudo apt update && sudo apt upgrade -y

Step 4: Install Node.js

Ghost requires Node.js. Install it using the NodeSource repository:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E
sudo apt-get install -y nodejs

Step 5: Install MySQL

sudo apt install mysql-server -y
sudo mysql_secure_installation

Follow the prompts to secure your MySQL installation.

Step 6: Create a MySQL Database for Ghost

sudo mysql

In the MySQL prompt, run:

CREATE DATABASE ghost_prod; CREATE USER 'ghost'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON ghost_prod.* TO 'ghost'@'localhost'; FLUSH PRIVILEGES; EXIT;

Step 7: Install Ghost-CLI

sudo npm install ghost-cli@latest -g

Step 8: Create a Directory for Ghost and Set Permissions

sudo mkdir -p /var/www/ghost
sudo chown $USER:$USER /var/www/ghost
sudo chmod 775 /var/www/ghost
cd /var/www/ghost

Step 9: Install Ghost

Follow the prompts, providing your blog URL, MySQL database details, and other configuration options.

Step 10: Configure Nginx (Optional)

If you chose to use Nginx during the Ghost installation:

  1. Ghost-CLI should have installed and configured Nginx for you.
  2. Verify the configuration:
sudo nano /etc/nginx/sites-available/ghost.conf
  1. If needed, adjust the server_name directive to match your domain.

Step 11: Set Up SSL with Let's Encrypt

Ghost-CLI can automatically set up SSL:

sudo ghost setup ssl

Step 12: Start Ghost

If Ghost isn't already running:

ghost start

Step 13: Access Your Ghost Admin Panel

Navigate to https://your_domain/ghost to access the admin panel and start customizing your blog.

Conclusion

You now have a fully functional Ghost blog running on DigitalOcean. Remember to keep your system and Ghost installation updated regularly for security and performance improvements.

For ongoing maintenance:

  • Start Ghost site:
ghost start
  • View Ghost status:
ghost status
  • Restart Ghost:
ghost restart
  • Stop Ghost process:
ghost stop

Troubleshooting Common Issues

When setting up a Ghost blog on DigitalOcean, you might encounter some issues. Here are common problems and their solutions:

1. Ghost Installation Fails

If the Ghost installation fails, it's often due to system requirements or permissions.

Fix:

  • Ensure your droplet meets the minimum requirements (1GB RAM, Ubuntu 20.04 LTS).
  • Check that you have the correct permissions:
sudo chown -R $USER:$USER /var/www/ghost

2. Database Connection Errors

These can occur if MySQL isn't properly configured or if the credentials are incorrect.

Fix:

  • Double-check your MySQL credentials.
  • Ensure MySQL is running:
sudo systemctl status mysql

If it's not running, start it:

sudo systemctl start mysql

3. Nginx Configuration Issues

Sometimes, Nginx might not be properly configured to serve your Ghost blog.

Fix:

  • Check the Nginx configuration:
sudo nano /etc/nginx/sites-available/ghost.conf
  • Ensure the server_name directive matches your domain.
  • Test the Nginx configuration:
sudo nginx -t

If there are no errors, restart Nginx:

sudo systemctl restart nginx

4. SSL Certificate Issues

If you're having trouble setting up SSL:

Fix:

  • Ensure your domain's DNS is properly configured and pointing to your DigitalOcean droplet.
  • Try setting up SSL manually:
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo certbot --nginx -d yourdomain.com
  • Check the Nginx configuration:
sudo nano /etc/nginx/sites-available/ghost.conf
  • Ensure the server_name directive matches your domain.
  • Test the Nginx configuration:
sudo nginx -t
  • If there are no errors, restart Nginx:

sudo systemctl restart nginx

4. SSL Certificate Issues

If you're having trouble setting up SSL:

Fix:

  • Ensure your domain's DNS is properly configured and pointing to your DigitalOcean droplet.
  • Try setting up SSL manually:
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo certbot --nginx -d yourdomain.com

5. Ghost Unable to Start

If Ghost fails to start after installation:

Fix:

  • Check the Ghost logs:
ghost log
  • Ensure Node.js is properly installed:
node --version
  • If necessary, reinstall Node.js following Step 4 in the main guide.

6. "ghost" Command Not Found

This can happen if Ghost-CLI isn't properly installed or isn't in your PATH.

Fix:

  • Reinstall Ghost-CLI:
sudo npm uninstall ghost-cli -g
sudo npm install ghost-cli@latest -g

7. Out of Memory Errors

If your blog crashes with out of memory errors:

Fix:

  • Consider upgrading your DigitalOcean droplet to a higher tier with more RAM.
  • Alternatively, set up a swap file:
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Then add the following line to /etc/fstab:

/swapfile none swap sw 0 0

8. Permissions Issues When Updating Ghost

If you encounter permissions errors when trying to update Ghost:

Fix:

  • Ensure the Ghost directory has the correct ownership:
sudo chown -R ghost:ghost /var/www/ghost
  • Then run the update command with sudo:
sudo -u ghost ghost update

Remember, when troubleshooting, always check the Ghost and Nginx error logs for specific error messages. These can provide valuable clues about the root cause of any issues.