How to Install Ghost Blogging Platform on Ubuntu 24.04 Server
Last Updated: May 19th, 2024
This tutorial will show you how to install the Ghost blogging platform on an Ubuntu 24.04 server. Ghost is an open-source blogging software coded in Node.js, allowing you to create modern, beautiful blogs. Compared to WordPress, Ghost is lightweight and much faster because it’s built specifically for blogging and isn’t a comprehensive content management system.
Ghost Features
Features of Ghost include:
- A Markdown-based editor that allows you to quickly write posts.
- Simple content management and collaborative editing with your team.
- Scheduled publishing and built-in analytics.
- Proper SEO built-in directly with semantic markup, permalinks, XML sitemaps, canonical tags, and automatic metadata with manual overrides.
- Integrated AMP (Accelerated Mobile Pages) support.
- Full RSS feeds, email subscription capture forms, and Slack webhook integration.
- Hundreds of beautiful free and premium themes available from the marketplace.
- A nice-looking default theme Casper with dark mode support.
- A cross-platform desktop app available for Linux, Mac, and Windows.
Requirements
To run a Ghost blog, you need a server with at least 1GB of RAM. You can use a Virtual Private Server (VPS) running an LTS version of Ubuntu like Ubuntu 24.04. You also need to have a domain name to utilize secure, encrypted connections.
Note: It is recommended to install Ghost with a non-root sudo user. To create and switch to a sudo user, run:
sudo adduser username
sudo adduser username sudo
su - username
Step 1: Update Ubuntu
If your server hasn’t been updated for some time, run the following command to update existing software packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Node.js on Ubuntu
Ghost requires the LTS version of Node.js. Currently, Ghost maintains optimal compatibility with Node.js v18.x. Add the NodeSource repository using the command below:
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Then install Node.js:
sudo apt install -y nodejs
You can check your Node and npm versions with:
node -v
npm -v
Step 3: Install MariaDB Database Server
Ghost supports MySQL and MariaDB. Run the following command to install the MariaDB database server on Ubuntu 24.04:
sudo apt install mariadb-server mariadb-client
After installation, verify that the service is running and enable it to start automatically at system boot:
systemctl status mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
Now run the post-installation security script:
sudo mysql_secure_installation
When prompted to enter the MariaDB root password, press Enter since it is not set yet. You can accept the defaults for the remaining prompts to secure your database instance.
Step 4: Create a Database and User for Ghost
Log in to the MariaDB console:
sudo mariadb -u root
Create a dedicated database and user for Ghost, granting all privileges to the user:
create database ghost;
grant all privileges on ghost.* to ghost@localhost identified by 'ghost_password';
flush privileges;
exit;
Step 5: Install Nginx Web Server
Ghost relies on Nginx, so install it using the following command:
sudo apt install nginx
If you are utilizing the UFW firewall, open ports 80 and 443:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Step 6: Create A Record For Your Blog Domain Name
Before moving forward, configure your DNS A record inside your domain control panel. The A record must point your target domain name to the public IP address of your Ubuntu server.
Step 7: Install Ghost on Ubuntu Server
Run the following command to install the official Ghost-CLI globally:
sudo npm install ghost-cli@latest -g
Create a directory for the installation and grant administrative permissions to your system user account (replace username with your real username):
sudo mkdir -p /var/www/ghost/
sudo apt install acl
sudo setfacl -R -m u:username:rwx /var/www/ghost/
sudo chmod 775 /var/www/ghost
Change your working directory and initiate the interactive installation process:
cd /var/www/ghost/
ghost install
During the process, the wizard will ask you for your configuration details:
? Enter your blog URL: https://yourdomain.com
? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghost
? Enter your MySQL password: ghost_password
? Enter your Ghost database name: ghost
Accept the prompt to automatically set up Nginx, Systemd, and SSL to secure your environment. Once done, complete configuration in your browser at https://yourdomain.com/ghost.
Step 8: Edit the Nginx Config File
To configure Nginx to serve both the www domain and the non-www domain, edit the main site configuration file:
sudo nano /etc/nginx/sites-enabled/yourdomain.com.conf
Modify the server_name line:
server_name yourdomain.com www.yourdomain.com;
Save and close the file. Delete the standalone configuration file that handles SSL paths separately:
sudo rm /etc/nginx/sites-enabled/yourdomain.com-ssl.conf
Install the Certbot client and obtain an updated TLS certificate handling both domain variants:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d yourdomain.com,www.yourdomain.com
sudo systemctl restart nginx
Step 9: Set Up Email Notification
To properly dispatch emails out of your Ghost platform for password resets or registrations, configure your transactional mail settings.
Option 1: Using an SMTP Relay Service
If you prefer an external SMTP relay layer, establish your configuration on the host environment and open your Ghost production config file:
sudo nano /var/www/ghost/config.production.json
Locate the "mail" block and update it as follows:
"mail": {
"transport": "Sendmail",
"from": "[email protected]"
},
Save changes and restart the Ghost service:
sudo systemctl restart ghost_yourdomain-com.service
Option 2: Using Your Own Custom Email Server
If you prefer using your own custom mail infrastructure, edit the configuration file:
sudo nano /var/www/ghost/config.production.json
Change the "mail" parameters to point to your secure SMTP server credentials:
"mail": {
"transport": "SMTP",
"from": "[email protected]",
"options": {
"service": "yourdomain.com",
"host": "mail.yourdomain.com",
"port": 465,
"secureConnection": true,
"auth": {
"user": "[email protected]",
"pass": "the_email_account_password"
}
}
},
Note: Ghost does not support port 587 for standard SMTP transport. Save the file and reload your configuration environment:
sudo systemctl restart ghost_yourdomain-com.service
Troubleshooting: How to Manually Set Up Nginx for Ghost
If the CLI environment skips Nginx configuration during automated installation steps, create the configuration block manually:
sudo nano /etc/nginx/conf.d/ghost.conf
Populate the block using the standard configuration syntax:
server {
listen [::]:80;
listen 80;
server_name example.com www.example.com;
root /var/www/ghost/;
access_log /var/log/nginx/ghost.access.log;
error_log /var/log/nginx/ghost.error.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:2368;
proxy_redirect off;
}
location ~ /.well-known {
allow all;
}
}
Save configurations, test the Nginx changes, and generate your TLS layer certificates via Certbot:
sudo nginx -t
sudo systemctl reload nginx
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d example.com,www.example.com
sudo systemctl restart nginx