Manually Deploying a Ghost Blog (Ubuntu 20.04)
Ghost is an open-source blog platform based on Node.js and makes writing and release more convenient. This section walks you through the deployment of a Ghost blog on an ECS running Ubuntu 20.04.
Creating a User
Performing operations as user root is not recommended by Ghost. You need to create a user and grant permissions to it.
- Run the following command to create a user: The following uses user as an example.
adduser user
The following information is displayed:
Adding user `user' ... Adding new group `user' (1000) ... Adding new user `user' (1000) with group `user' ... Creating home directory `/home/user' ... Copying files from `/etc/skel' ... New password: Retype new password: passwd: password updated successfully Changing the user information for user Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] Y
- In the New password: and Retype new password: lines, enter and confirm the user password (not displayed by default) as prompted, and press Enter.
- In the Enter the new value, or press ENTER for the default line, press Enter to retain the default settings. You can also specify the information as needed.
- In the Is the information correct? [Y/n] line, press Y to confirm the information and press Enter to complete the settings.
- Run the following command to add the newly created user to the user group:
- Run the following command to switch to user:
su - user
Installing Nginx
Before deploying the Ghost blog, you need to install Nginx and use it as an HTTP server. The following uses Nginx 1.18.0 as an example.
- Run the following commands to update the Linux OS and software package:
sudo apt-get upgrade -y
- Run the following command to install Nginx:
- Run the following command to check the Nginx version:
The following information is displayed:
nginx version: nginx/1.18.0 (Ubuntu)
- (Optional) Configure the firewall.
Uncomplicated Firewall (UFW) is an iptables interface that simplifies the firewall configuration. By default, Ubuntu has UFW installed. Run the following command to check the firewall status:
sudo ufw status
If you do not want to enable the firewall, skip this step. If you want to enable the firewall, run the following command:
sudo ufw enable
Verify that the firewall is enabled.
Before testing Nginx, you need to reconfigure the firewall to allow access to Nginx. Run the following command to automatically register Nginx with UFW:
sudo ufw app list
The following information is displayed:
Available applications: Nginx Full Nginx HTTP Nginx HTTPS ...
- Nginx Full: Port 80 is enabled to distribute normal and unencrypted web traffic, and port 443 to distribute TLS/SSL-encrypted traffic.
- Nginx HTTP: Port 80 is enabled to distribute normal and unencrypted web traffic.
- Nginx HTTPS: Port 443 is enabled to distribute TLS/SSL-encrypted traffic.
Run the following command to ensure that the firewall allows HTTP and HTTPS connections:
sudo ufw allow 'Nginx Full'
- Verify that Nginx can work properly.
Use the domain name or IP address to access Nginx. The Welcome to nginx page is displayed if Nginx is started normally.
Enter http://IP address of the Nginx server in the address bar to access Nginx. If the following page is displayed, Nginx has been installed.
Installing MySQL
MySQL is an open-source database management system, which is usually installed as a part of the popular LAMP (Linux, Apache, MySQL, and PHP/Python/Perl) stack. MySQL uses relational databases and the structured query language (SQL) to manage data.
- Run the following command to install MySQL:
- Run the following command to check the MySQL version:
The following information is displayed:
mysql Ver 8.0.37-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
- Run the following command to access MySQL:
- Create a database for Ghost. The following uses ghost_data as an example.
CREATE DATABASE ghost_data;
- Run the following commands to set the password for user root:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxx';
In the preceding command, xxxxx indicates the password you set for user root.
- Run the following command to reload the privilege tables of MySQL to check that the change takes effect:
- Run the following command to exit MySQL:
Installing Node.js
- Run the following commands to install Node.js:
sudo curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
- Run the following commands to view the versions of Node.js and Node Package Manager (npm), respectively:
npm -v
The following information is displayed:
root@ecs-c47c:~# node -v v18.20.3 root@ecs-c47c:~# npm -v 10.7.0
Installing and Configuring Ghost
Ghost-CLI has been added to Ghost v1.0.0 and later versions. You can directly install and configure Ghost-CLI.
- Run the following command to install Ghost-CLI:
- Create a folder named ghost under /var/www/.
sudo mkdir -p /var/www/ghost
If ghost is created under /root, Ghost cannot work properly.
- Run the following command to grant user permissions to ghost:
sudo chown user:user /var/www/ghost
sudo chmod 775 /var/www/ghost
user is created in step 1.
- Run the following command to switch to the created folder:
- Run the following command to install Ghost using Ghost-CLI:
- Configure Ghost.
If ghost install is successfully executed in /var/www/ghost/, follow the prompts to configure related parameters.
- Enter your blog URL: Enter a resolved domain name, for example, http://example.com.
- Enter your MySQL hostname: Enter the database connection address. In this example, the MySQL database and Ghost are deployed on the same ECS. Press Enter to retain the default settings.
- Enter your MySQL username: Enter the database username root and press Enter.
- Enter your MySQL password: Enter the database password set in step 5 and press Enter.
- Enter your Ghost database name: Enter the name of the database used by Ghost. Enter ghost_data and press Enter.
To modify the configuration, run the following command:
vi config.production.json
The following example is for your reference.
Verifying Blog Access
If Ghost is successfully installed, you can access the Ghost blog using the domain name.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.