Ghost is a free and excellent open source blog platform developed based on Node.js, with instant preview, extreme simplicity, and multi-user support. This section will guide users to deploy Ghost blog on a cloud server instance of the Ubuntu20.04 operating system.
Before You Begin
To use the steps in this section, the ECS instance must meet the following prerequisites:
· The instance needs to be assigned a public IP or bound to an elastic IP.
· Operating system: Ubuntu 16.04, Ubuntu 18.04, Ubuntu 20.04, Ubuntu 22.04.
· The inbound security rules of the security group where the instance is located release ports 22, 80, 4423, and 2368.
Create a new user
Since Ghost officially does not recommend using the root user to do this directly. Therefore, you need to create a new user and configure permissions for it.
1. Execute the following command to create a new user.
Take creating a test user as an example.
adduser test
The specific configuration is as follows:
root@ecm-2d20-Ghost: ~# adduser test
Adding user `test' ...
Adding new group `test' (1000) ...
Adding new user `test' (1000) with group `test' ...
Creating home directory `/home/test' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for test
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
2. Execute the following command to add the newly created user to the group.
usermod -a -G sudo test
Execute the following command to switch to the test user.
su - test
Install gcc and g++
1. Execute the following command to install common development and compilation tools.
sudo apt-get install build-essential
2. Execute the following command to install gcc.
apt-get install gcc
3. Execute the following command to view the gcc version.
gcc --version
Echo message:
root@ecm-da5b: ~# gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
4. Execute the following command to install g++.
sudo apt-get install g++
5. Use the following command to view the g++ version.
g++ --version
Echo message:
root@ecm-da5b: ~# g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
Install Node.js
Before installing Ghost, you need to install the Node.js required by Ghost.
1. Execute the following command to download the Node.js installation source.
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
2. Execute the following command to install Node.js.
sudo apt-get install -y nodejs
3. After the Node.js installation is complete, execute the following command to view the Node.js version and npm version.
node -v
npm –v
Echo message:
test@ecm-2d20-Ghost: ~$ node -v
v16.20.2
test@ecm-2d20-Ghost: ~$ npm -v
8.19.4
Install Nginx
To deploy Ghost blog, you need to install Nginx as HTTP server.
1. Execute the following command to install Nginx.
sudo apt-get update
sudo apt-get install nginx
2. After the installation is complete, execute the following command to view the Nginx version.
nginx –v
Echo message is as follows:
test@ecm-2d20-Ghost: ~$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
3. Verify that Nginx starts normally.
Enter the public IP address or domain name in the browser to access Nginx. If the following page appears, it means that Nginx is installed successfully.
4. Modify the Nginx configuration (optional).
Enter the following command to modify the configuration file.
vim /etc/nginx/nginx.conf
Enter the following:
server {
listen 8001; //listen port number In this section, we chose to listen on port 8001 to avoid the problem of port 80 conflicts.
server_name 171.111.xxx.xxx; #Write your domain name or IP address here
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
Install MySQL
1. Execute the following command to install MySQL.
sudo apt-get install -y mysql-server
2. Enter the following command to view the MySQL version.
mysql –V
Echo message is as follows:
root@ecm-da5b: ~# mysql -V
mysql Ver 8.0.34-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
3. Open the MySQL console
Usually, after MySQL is newly installed on Ubuntu without any configuration, users accessing the server will be authenticated using the auth_socket (authentication socket) plug-in.
The use of auth_socket prevents the server from authenticating the user with a password. Not only does it cause security issues, but it also prevents users from accessing the database using external programs. So we need to change the authentication method from auth_socket to use mysql_native_password (password authentication). Enter the following command to open the MySQL console.
sudo mysql
4. Set the root user password.
Enter the following command to change the MySQL authentication method from auth_socket to mysql_native_password (password authentication)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ' Enter the password of the root account'
5. Execute the following command to create the database used by Ghost.
This section takes ghost as an example
create database ghost
6. Enter the following command to view the database creation.
show databases
Echo message:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| ghost |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
7. Execute the following command to exit MySQL.
exit
8. To avoid possible Chinese garbled characters in the database, you can execute the following command to set the MySQL encoding.
sudo vi /etc/my.cnf
Enter the following, then save and exit.
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
9. Execute the following command to restart MySQL to take effect
sudo /usr/sbin/service mysql restart
Install Ghost
1. Enter the following command to create the Ghost-CLI command tool to quickly configure Ghost.
sudo npm install ghost-cli@latest -g
2. Execute the following commands in sequence to create the Ghost installation directory and authorize it.
sudo mkdir -p /var/www/ghost
sudo chown test:test /var/www/ghost //Configure permissions
sudo chmod 775 /var/www/ghost
3. Execute the following command to enter the created folder and install Ghost.
cd /var/www/ghost
ghost install
Some configuration parameters are as follows:
Enter your blog URL: Please enter the resolved domain name or public IP and enter http://(domain name or public IP address).
Enter your MySQL hostname: Please enter the database connection address, enter localhost, and press Enter.
Enter your MySQL username: Please enter the database user name, enter root and press Enter.
Enter your MySQL password: Please enter the database password, enter the password that was set in the root account, and press Enter.
Enter your database name: Please enter the name of the database used by Ghost, enter the Ghost that was created in the database, and press Enter.
After that, there will be some parameters to configure, you can set them as needed, in this section, all enter yes.
4. Test access to the Ghost blog.
Visit the Ghost front page.
In any server with access to the Internet, open a browser and enter the public IP address or domain name of the cloud server instance to access the front page of Ghost.
For example: http://public IP address or domain name
If you want to enter the administrator background, you only need to add /ghost to the end of the domain name or the public IP address to enter, and you need to register an account for the first time, and then you can enter the background.
For example: https://public IP or domain name/ghost