How to Install Ghost on Ubuntu 23.04
Ghost is a free and open-source blogging platform written in JavaScript and distributed under the MIT License, designed to simplify the process of online publishing for individual bloggers as well as online publications.
Update the System.
apt update -y
Create a Sudo User
We will install and configure the Ghost packages under this sudo
user.
Use the adduser
command to add a new user to your system.
adduser ghostadmin
Update the password using the passwd
command,
passwd ghostadmin
Use the usermod
command to add the user to the wheel group.
usermod -aG sudo ghostadmin
On Ubuntu, members of the Sudo group have sudo
privileges.
Use su
command to switch to the new user account.
su - ghostadmin
We are using ghostadmin as the
sudo
user. You can have any other name of your choice. Every command executed here after will be underghostadmin
user.
Install NGINX
sudo apt-get install nginx
If ufw was activated, the firewall allows HTTP and HTTPS connections.
sudo ufw allow 'Nginx Full'
Install Database Server
Install a database server for Ghost CMS. This can either be MySQL or MariaDB database server.
In this example, we will choose MariaDB, it is a popular database server. The installation is simple and requires just a few steps as shown below,
sudo apt-get install mysql-server
Output:
ghostadmin@ubuntu:~$ apt-get install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libcgi-fast-perl libcgi-pm-perl libencode-locale-perl
libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl
mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0
mysql-client-core-8.0 mysql-common mysql-server-8.0
mysql-server-core-8.0
Suggested packages:
libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx
tinyca
The following NEW packages will be installed:
libcgi-fast-perl libcgi-pm-perl libencode-locale-perl
libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl
mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0
mysql-client-core-8.0 mysql-common mysql-server
mysql-server-8.0 mysql-server-core-8.0
When the installation is completed, Create the database for the ghost blog.
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'StrongPassword';
QUIT
Replace
StrongPassword
with a better one.
Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB, and verify the status using the commands below.
sudo service mysql start
sudo service mysql restart
sudo service mysql status
Output:
ghostadmin@ubuntu:~$ sudo service mysql start
ghostadmin@ubuntu:~$ sudo service mysql restart
ghostadmin@ubuntu:~$ sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; v>
Active: active (running) since Thu 2021-11-11 16:58:04 UTC; 9>
Process: 61722 ExecStartPre=/usr/share/mysql/mysql-systemd-sta>
Main PID: 61740 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 1072)
Memory: 354.5M
CGroup: /system.slice/mysql.service
└─61740 /usr/sbin/mysqld
Install Latest Version of Node.js
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash
sudo apt-get install -y nodejs
Output:
root@ubuntu:~# sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libc-ares2 libnode108 node-acorn node-busboy node-cjs-module-lexer node-undici node-xtend nodejs-doc
Suggested packages:
npm
The following NEW packages will be installed:
libc-ares2 libnode108 node-acorn node-busboy node-cjs-module-lexer node-undici node-xtend nodejs nodejs-doc
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/15.5 MB of archives.
After this operation, 68.8 MB of additional disk space will be used.
Selecting previously unselected package libc-ares2:amd64.
(Reading database ... 119900 files and directories currently installed.)
Preparing to unpack .../0-libc-ares2_1.18.1-2_amd64.deb ...
Unpacking libc-ares2:amd64 (1.18.1-2) ...
Selecting previously unselected package node-xtend.
Preparing to unpack .../1-node-xtend_4.0.2-3_all.deb ...
Install Ghost-CLI
Ghost-CLI is a command-line interface (CLI) tool that makes installing and updating Ghost easy.
Install Ghost-CLI.
sudo apt install npm
sudo npm install -g ghost-cli@latest
Setting File Permissions
Replace dev.domainhere.info with your actual domain name.
Create the document root directory for a ghost.
sudo mkdir -p /var/www/dev.domainhere.info
Change ownership and permission of the /var/www/dev.domainhere.info
.
sudo chown ghostadmin:ghostadmin /var/www/dev.domainhere.info
sudo chmod 775 /var/www/dev.domainhere.info
Enter to the dev.domainhere.info
root directory:
Install Ghost
cd /var/www/dev.domainhere.info
Ensure that the directory is empty.
Let us now install Ghost on the directory by running the below command,
ghost install
Output:
ghostadmin@vps:/var/www/dev.domainhere.info $ ghost install
✔ Checking system Node.js version - found v18.13.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.44.0
✔ Finishing install process
? Enter your blog URL: http://dev.domainhere.info
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: dev.domainhere.info_prod
✔ Configuring Ghost
✔ Setting up instance
+ sudo useradd --system --user-group ghost
+ sudo chown -R ghost:ghost /var/www/dev.domainhere.info/content
✔ Setting up "ghost" system user
? Do you wish to set up "ghost" mysql user? Yes
✔ Setting up "ghost" mysql user
? Do you wish to set up Nginx? Yes
+ sudo mv /tmp/dev.domainhere.info/dev.domainhere.info.conf /etc/nginx/sites-available/dev.domainhere.info.conf
+ sudo ln -sf /etc/nginx/sites-available/dev.domainhere.info.conf /etc/nginx/sites-enabled/dev.domainhere.info.conf
+ sudo nginx -s reload
✔ Setting up Nginx
? Do you wish to set up SSL? Yes
? Enter your email (For SSL Certificate) Your_Email@gmail.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 dev.domainhere.info --webroot /var/www/dev.domainhere.info/system/nginx-root --reloadcmd "nginx -s reload" --accountemail your_email@gmail.com
? Do you wish to set up SSL? Yes
? Enter your email (For SSL Certificate) Your_Email@gmail.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 dev.domainhere.info --webroot /var/www/dev.domainhere.info/system/nginx-root --reloadcmd "nginx -s reload" --accountemail Your_Email@gmail.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/dev.domainhere.info/dev.domainhere.info-ssl.conf /etc/nginx/sites-available/dev.domainhere.info-ssl.conf
+ sudo ln -sf /etc/nginx/sites-available/dev.domainhere.info-ssl.conf /etc/nginx/sites-enabled/dev.domainhere.info-ssl.conf
+ sudo nginx -s reload
✔ Setting up SSL
? Do you wish to set up Systemd? Yes
+ sudo mv /tmp/dev.domainhere.info/ghost_dev.domainhere.info.service /lib/systemd/system/ghost_dev.domainhere.info.service
+ sudo systemctl daemon-reload
✔ Setting up Systemd
+ sudo systemctl is-active ghost_dev.domainhere.info
? Do you want to start Ghost? Yes
+ sudo systemctl start ghost_dev.domainhere.info
☱ Starting Ghost
+ sudo systemctl is-enabled ghost_dev.domainhere.info
+ sudo systemctl enable ghost_dev.domainhere.info --quiet
✔ Starting Ghost
Access Ghost CMS Dashboard
To complete the setup of your publication, visit: http://dev.domainhere.info/ghost
Replace dev.domainhere.info with your actual domain.
Create your first Ghost administrator/publisher account by clicking on “Create your account”.
You’ll get to the Ghost CMS dashboard in a few
Done.