How to Install Ghost on Ubuntu 22.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@vps:~$ 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 'password';
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@vps:~$ sudo service mysql start
ghostadmin@vps:~$ sudo service mysql restart
ghostadmin@vps:~$ 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:
ghostadmin@vps:~$ sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.8 MB of archives.
After this operation, 120 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_16.x focal/main amd64 nodejs amd64 16.13.0-deb-1nodesource1 [25.8 MB]
Fetched 25.8 MB in 1s (29.0 MB/s)
Selecting previously unselected package nodejs.
(Reading database ... 71584 files and directories currently installed.)
Preparing to unpack .../nodejs_16.13.0-deb-1nodesource1_amd64.deb ...
Install Ghost-CLI
Ghost-CLI is a command-line interface (CLI) tool that makes installing and updating Ghost easy.
Install Ghost-CLI.
sudo npm install -g ghost-cli@latest
Setting File Permissions
Replace example.com with your actual domain name.
Create the document root directory for a ghost.
sudo mkdir -p /var/www/example.com
Change ownership and permission of the /var/www/example.com
.
sudo chown ghostadmin:ghostadmin /var/www/example.com
sudo chmod 775 /var/www/example.com
Enter to the example.com
root directory:
Install Ghost
cd /var/www/example.com
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/example.com$ ghost install
✔ Checking system Node.js version - found v16.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 v4.22.1
✔ Finishing install process
? Enter your blog URL: http://example.com
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: example.com_prod
✔ Configuring Ghost
✔ Setting up instance
+ sudo useradd --system --user-group ghost
+ sudo chown -R ghost:ghost /var/www/example.com/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/example.com/example.com.conf /etc/nginx/sites-available/example.com.conf
+ sudo ln -sf /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.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 example.com --webroot /var/www/example.com/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 example.com --webroot /var/www/example.com/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/example.com/example.com-ssl.conf /etc/nginx/sites-available/example.com-ssl.conf
+ sudo ln -sf /etc/nginx/sites-available/example.com-ssl.conf /etc/nginx/sites-enabled/example.com-ssl.conf
+ sudo nginx -s reload
✔ Setting up SSL
? Do you wish to set up Systemd? Yes
+ sudo mv /tmp/example.com/ghost_example.com.service /lib/systemd/system/ghost_example.com.service
+ sudo systemctl daemon-reload
✔ Setting up Systemd
+ sudo systemctl is-active ghost_example.com
? Do you want to start Ghost? Yes
+ sudo systemctl start ghost_example.com
☱ Starting Ghost
+ sudo systemctl is-enabled ghost_example.com
+ sudo systemctl enable ghost_example.com --quiet
✔ Starting Ghost
Access Ghost CMS Dashboard
To complete the setup of your publication, visit: http://example.com/ghost
Replace example.com 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.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS