Ghost is a free and open-source content management system (CMS) used for hosting a website. It is mainly used for publishing newsletters, articles, blog post content and etc.
Ghost relies entirely on JavaScript, and the server side uses Node.js, while the admin interface uses Ember.js.
The data is stored in the MySQL database. In this blog post, we will install the Nginx web server along with MySQL required for Ghost to function properly.
In this tutorial, we are going to show you how to install Ghost on Ubuntu 22.04 OS. Let’s get things done!
Table of Contents
Prerequisites
- Fresh install of Ubuntu 22.04
- A valid domain pointed to the server IP address
- User privileges: root or non-root user with sudo privileges
Step 1. Update the System
Before we start with Ghost installation, we will update the system packages to the latest versions available.
sudo apt update -y && sudo apt upgrade -y
Step 2. Install Nginx
To install the Nginx web server execute the following command:
sudo apt-get install nginx -y
After successful installation, the Nginx service will be automatically started. To check the status of Nginx, execute the following command:
sudo systemctl status nginx
You should get the following output:
root@host:~# sudo systemctl status nginx ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2022-12-28 15:27:57 CST; 10s ago Docs: man:nginx(8) Process: 8663 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 8664 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 8760 (nginx) Tasks: 4 (limit: 4575) Memory: 4.8M CPU: 50ms CGroup: /system.slice/nginx.service
Step 3. Install MySQL server
To install MySQL execute the following command:
sudo apt install mysql-server -y
Once installed, start and enable the MySQL service:
systemctl start mysql.service && systemctl enable mysql.service
To check the status of the service:
systemctl status mysql.service
If everything is ok, you should get the following output:
root@host:~# systemctl status mysql.service ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2022-12-28 15:32:20 CST; 13s ago Main PID: 9547 (mysqld) Status: "Server is operational" Tasks: 39 (limit: 4575) Memory: 364.1M CPU: 1.258s CGroup: /system.slice/mysql.service └─9547 /usr/sbin/mysqld
Step 4. Create a Ghost database and user
Next, we need to create a Ghost database, the Ghost user, and grant the permissions for that user to the database.
CREATE USER 'ghost'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere'; CREATE DATABASE ghost; GRANT ALL PRIVILEGES ON ghost.* TO 'ghost'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 5. Install Nodejs and npm
To install nodejs and npm, execute the following commands:
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash sudo apt-get update sudo apt-get install nodejs sudo npm install npm@latest -g
You can check the versions of Nodejs and NPM with the following command:
node --version && npm --version
You will get the following output:
root@host:~# node --version && npm --version v16.19.0 9.2.0
Step 6. Install Ghost-CLI and Ghost
First, we need to install the Ghost client command line tool, so we can install Ghost later:
sudo npm install -g ghost-cli@latest
To check the Ghost client version, execute the following:
ghost -v
You will get the following output:
Ghost-CLI version: 1.23.1
Now, when we have all dependencies installed, we can finally install Ghost. To create a Ghost user:
adduser ghostuser usermod -aG sudo ghostuser
Login with the newly created Ghost user, create a ghost directory, and set the right permission:
su - ghostuser sudo mkdir -p /var/www/ghost sudo chown ghostuser:ghostuser /var/www/ghost sudo chmod 775 /var/www/ghost
Go into the Ghost directory and install Ghost with the following command:
cd /var/www/ghost/ ghost install
The installation will start, and you will be asked to specify the domain name, MySQL host, database name, database user, password and to confirm the Nginx web server, SSL certificate and etc.
✔ Checking system Node.js version - found v16.19.0 ✔ Checking logged in user ✔ Checking current folder permissions ✔ Checking system compatibility ✔ Checking for a MySQL installation ✔ Checking memory availability ✔ Checking free space ✔ Checking for latest Ghost version ✔ Setting up install directory ✔ Downloading and installing Ghost v5.26.3 ✔ Finishing install process ? Enter your blog URL: http://yourdomain.com ? Enter your MySQL hostname: localhost ? Enter your MySQL username: ghost ? Enter your MySQL password: [hidden] ? Enter your Ghost database name: ghost ✔ Configuring Ghost ✔ Setting up instance + sudo useradd --system --user-group ghost + sudo chown -R ghost:ghost /var/www/ghost/content ✔ Setting up "ghost" system user ℹ Setting up "ghost" mysql user [skipped] ? Do you wish to set up Nginx? Yes + sudo mv /tmp/yourdomain-com/yourdomain.com.conf /etc/nginx/sites-available/yourdomain.com.conf + sudo ln -sf /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/yourdomain.com.conf + sudo nginx -s reload ✔ Setting up Nginx ? Do you wish to set up SSL? (Y/n) Y ? Enter your email (For SSL Certificate) admin@yourdomain.com + sudo mkdir -p /etc/letsencrypt + sudo ./acme.sh --install --home /etc/letsencrypt + sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --server letsencrypt --domain yourdomain.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail admin@yourdomain.com + sudo openssl dhparam -dsaparam -out /etc/nginx/snippets/dhparam.pem 2048 + sudo mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf + sudo mv /tmp/yourdomain-com/yourdomain.com-ssl.conf /etc/nginx/sites-available/yourdomain.com-ssl.conf + sudo ln -sf /etc/nginx/sites-available/yourdomain.com-ssl.conf /etc/nginx/sites-enabled/yourdomain.com-ssl.conf + sudo nginx -s reload ✔ Setting up SSL ? Do you wish to set up Systemd? (Y/n) Y ? Do you wish to set up Systemd? Yes + sudo mv /tmp/yourdomain-com/ghost_yourdomain-com.service /lib/systemd/system/ghost_yourdomain-com.service + sudo systemctl daemon-reload ✔ Setting up Systemd + sudo systemctl is-active yourdomain-com ? Do you want to start Ghost? Yes + sudo systemctl start ghost_yourdomain-com ☱ Starting Ghost Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail ------------------------------------------------------------------------------ Ghost was installed successfully! To complete setup of your publication, visit: http://yourdomain.com/ghost/
After successful installation, you can access the website at http://yourdomain.com/ghost/ to define the name of the website and set up the login credentials.
Once done, click on the black button “Create account & start publishing ->“
That’s it; you successfully installed and configured Ghost on Ubuntu 22.04. Of course, you do not have to do this if you find the setup complex. You can always contact our Technical support. We are available 24/7 and will help you with any Ghost installation and configuration aspect.
If you liked this about installing Ghost on Ubuntu 22.04, please share it with your friends on social networks or simply leave a reply below. Thanks.