How To Install Ghost on Debian 12
Ghost is a powerful, open-source content management system (CMS) designed for creating and managing modern websites, blogs, and online publications. Known for its simplicity, speed, and flexibility, Ghost has become a popular choice among bloggers, journalists, and businesses looking for an efficient platform to share their content.
In this comprehensive guide, we’ll walk you through the process of installing Ghost on Debian 12, also known as Debian Bookworm. Debian is renowned for its stability and security, making it an excellent choice for hosting Ghost. By the end of this tutorial, you’ll have a fully functional Ghost installation ready to power your website or blog.
Prerequisites
Before we begin the installation process, ensure you have the following:
- A Debian 12 server with at least 1GB of RAM and 10GB of storage
- Root access or a user with sudo privileges
- A domain name pointed to your server’s IP address
- Basic familiarity with the Linux command line
It’s also recommended to have a basic understanding of web servers and databases, as we’ll be working with Nginx and MySQL throughout this tutorial.
Preparing the Debian 12 Server
Let’s start by updating your Debian 12 system and installing some essential packages:
sudo apt update
sudo apt upgrade -y
sudo apt install curl software-properties-common apt-transport-https ca-certificates gnupg2 -y
Next, we’ll set up a firewall using UFW (Uncomplicated Firewall) to enhance security:
sudo apt install ufw -y
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
This configuration allows SSH, HTTP, and HTTPS traffic while blocking other incoming connections.
Installing Node.js
Ghost requires Node.js to run. Let’s install the latest LTS (Long Term Support) version:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y
Verify the installation by checking the Node.js and npm versions:
node --version
npm --version
Setting Up MySQL Database
Ghost uses MySQL as its database. Install and secure MySQL with these commands:
sudo apt install mysql-server -y
sudo mysql_secure_installation
Follow the prompts to set a root password and secure your MySQL installation. Next, create a database and user for Ghost:
sudo mysql -u root -p
Once logged in to MySQL, run these commands:
CREATE DATABASE ghostdb;
CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON ghostdb.* TO 'ghostuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace ‘your_strong_password’ with a secure password of your choice.
Installing Nginx Web Server
Nginx will serve as our web server and reverse proxy for Ghost. Install it using these commands:
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
Verify that Nginx is running by visiting your server’s IP address in a web browser. You should see the default Nginx welcome page.
Installing Ghost-CLI
Ghost-CLI is a command-line tool that simplifies the process of installing and managing Ghost. Install it globally using npm:
sudo npm install ghost-cli@latest -g
Verify the installation:
ghost --version
Installing Ghost CMS
Now, let’s install Ghost itself. First, create a directory for your Ghost installation:
sudo mkdir -p /var/www/ghost
sudo chown $USER:$USER /var/www/ghost
sudo chmod 775 /var/www/ghost
cd /var/www/ghost
Run the Ghost installation wizard:
ghost install
Follow the prompts, providing the following information:
- Blog URL (e.g.,
https://yourdomain.com
) - MySQL hostname (localhost)
- MySQL username and password (created earlier)
- Ghost database name (
ghostdb
)
The installer will set up Ghost and its dependencies automatically.
Configuring Nginx for Ghost
Create a new Nginx server block configuration for Ghost:
sudo nano /etc/nginx/sites-available/ghost
Add the following configuration, replacing ‘yourdomain.com’ with your actual domain:
server {
listen 80;
server_name yourdomain.com;
location / {
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;
}
client_max_body_size 50m;
}
Enable the new configuration and restart Nginx:
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Securing Ghost with SSL/TLS
To enable HTTPS, we’ll use Let’s Encrypt to obtain a free SSL certificate. First, install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Obtain and install the SSL certificate:
sudo certbot --nginx -d yourdomain.com
Follow the prompts to complete the SSL configuration. Certbot will automatically update your Nginx configuration to use HTTPS.
Starting and Managing Ghost
Ghost should now be running. You can manage it using the following commands:
ghost start # Start Ghost
ghost stop # Stop Ghost
ghost restart # Restart Ghost
ghost status # Check Ghost status
To ensure Ghost starts automatically on system boot:
sudo systemctl enable ghost_yourdomain-com
Troubleshooting Common Issues
If you encounter issues during the installation or operation of Ghost, consider the following troubleshooting steps:
Permission Problems
Ensure the Ghost directory has the correct permissions:
sudo chown -R $USER:$USER /var/www/ghost
sudo find /var/www/ghost -type d -exec chmod 775 {} \;
sudo find /var/www/ghost -type f -exec chmod 664 {} \;
Database Connection Issues
If Ghost can’t connect to the database, verify your MySQL credentials and ensure the MySQL service is running:
sudo systemctl status mysql
mysql -u ghostuser -p -e "USE ghostdb; SHOW TABLES;"
Nginx Configuration Errors
Check Nginx error logs for any configuration issues:
sudo tail -f /var/log/nginx/error.log
Ensure your Nginx configuration is correct by running:
sudo nginx -t
Congratulations! You have successfully installed Ghost. Thanks for using this tutorial for installing Ghost CMS on Debian 12 system. For additional help or useful information, we recommend you check the official Ghost website.