×
Community Blog Set up a Ghost Site on ECS

Set up a Ghost Site on ECS

This article describes how to set up a Ghost site on an Elastic Compute Service (ECS) instance that runs Ubuntu 20.04.

By Alibaba Cloud ECS Team

Ghost is a free, open source blogging platform developed based on Node.js. This platform is used to simplify the process of writing and publishing blogs. This article describes how to set up a Ghost site on an Elastic Compute Service (ECS) instance that runs Ubuntu 20.04.

Background Information

Ghost sites can run in development or production mode. The first time you set up a Ghost site, we recommend that you run the site in development mode to make the site easy to debug. The procedure described in this article is applicable to individual users who are new to using Alibaba Cloud to build websites. For more information about Ghost sites, see Getting started with Ghost.

You can use Alibaba Cloud services to scale up or out your service capacity based on your business needs. Examples:

• Scale up the vCPUs and memory of a single ECS instance to enhance the processing performance of the instance.

• Add multiple ECS instances to the backend server groups of a Server Load Balancer (SLB) instance and use the SLB instance to load-balance the traffic to ECS instances.

• Use Alibaba Cloud Auto Scaling to automatically increase or decrease the number of ECS instances on demand.

• Use Object Storage Service (OSS) buckets to store large volumes of data, such as static web pages, pictures, and videos.

Preparations

An ECS instance that uses the following configurations is created:

• The instance has a public IP address or an elastic IP address (EIP). For more information, see Associate an EIP.

• Operating system: Ubuntu 16.04, 18.04, 20.04, or 22.04.

Note: In this article, an ECS instance that runs Ubuntu 20.04 is used. Software package versions may vary slightly based on Ubuntu versions.

• An inbound rule is added to a security group of the ECS instance to open port 22, port 80, port 443, and port 2368. For more information, see Add a security group rule.

(Optional) Step 1: Create a User

Note: If you configured ecs-user as the logon username of the ECS instance during instance creation, skip this step and proceed to Step 2: Install NGINX.

Ghost recommends that you do not use the root user to build the Ghost site. Create a user on the ECS instance and grant permissions to the user.

1.  Log on to the ECS instance remotely.

For more information, see Connect to a Linux instance by using a password or key.

2.  Run the following command to create a new user: In this example, the test user is created.

adduser test

a) When the New password: and Retype new password: messages appear, enter and confirm a password. By default, the characters of the password are hidden when you enter the password. After you confirm the password, press the Enter key.

b) When the Enter the new value, or press ENTER for the default message appears, press the Enter key to accept the default value. Alternatively, you can also fill in the user information according to the actual situation.

c) When the Is the information correct? [Y/n] message appears, enter Y to confirm the information and press the Enter key to complete the configuration.

The following code shows how to configure a new user:

root@iZbp1g2d4dpki2mf63b****:~# 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

3.  Run the following command to add the new user to a group:

usermod -a -G sudo test

4.  Run the following command to switch to the test user:

su - test

Step 2: Install NGINX

Note: Make sure that your ECS instance is assigned a public IP address or bound with an Elastic IP Address address (EIP). For more information, see Associate an EIP.

To build a Ghost site, you must install NGINX to use it as an HTTP server.

1.  Run the following commands in sequence to update the Linux operating system and software package.

sudo apt-get update
sudo apt-get upgrade -y

2.  Install NGINX.

sudo apt-get install -y nginx

After NGINX is installed, run the nginx –v command to check the version of NGINX.

test@iZbp1g2d4dpki2mf63b****:$ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)

Note: In this example, NGINX 1.18.0 is installed. The software installation package is updated from time to time. The version of NGINX that you install may be different.

Step 3: Install MySQL

MySQL is an open source database management system and is often installed as part of the popular LAMP (Linux, Apache, MySQL, and PHP/Perl/Python) stack. MySQL uses relational databases and SQL statements to manage data.

1.  Run the following command to install MySQL:

sudo apt-get install -y mysql-server

Run the mysql –V command to check the version of MySQL. A command output similar to the following one indicates that MySQL is installed.

test@iZbp1g2d4dpki2mf63b****:~$ mysql -V
mysql  Ver 8.0.33-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))

2.  Run the following command to connect to MySQL:

Ubuntu 18.04/20.04/22.04

sudo mysql

Ubuntu 16.04

mysql -u root -p

3.  Run the following command to create a database for Ghost:

In this example, a database named ghost_data is created.

CREATE DATABASE ghost_data;

4. (Optional) If the ECS instance runs Ubuntu 18.04, 22.04, or 22.04, run the following command to configure the password of the root user:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Enter the password for the root user',

5.  Run the following command to exit MySQL:

exit

Step 4: Install Node.js

Before you install Ghost, install Node.js that is required for Ghost.

1.  Run the following command to download the Node.js installation source:

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash

2.  Run the following command to install Node.js:

sudo apt-get install -y nodejs

3.  Run the following command to view the Node.js version:

node -v

A command output similar to the following one is returned:

test@iZbp1g2d4dpki2mf63b****:~$ node -v
v16.20.1

Step 5: Install Ghost

1.  Install the Ghost-CLI command line tool to quickly configure Ghost.

sudo npm install ghost-cli@latest -g

2.  Run the following commands in sequence to create a directory in which to install Ghost and grant permissions on the directory:

sudo mkdir -p /var/www/ghost
sudo chown test:test /var/www/ghost
sudo chmod 775 /var/www/ghost

3.  Run the following commands in sequence to install Ghost:

cd /var/www/ghost
ghost install

Some parameters must be specified during the Ghost installation process, as shown in the following figure.

1

Description of the parameters:

  • Enter your blog URL: Enter a resolved domain name of Ghost. Example: http://exapmle.com.

In this example, http://47.98.XX.XX is entered.

  • Enter your MySQL hostname: Enter the hostname of the ECS instance on which the database is installed. In this example, press the Enter key to accept the default value because the MySQL database and Ghost are installed on the same ECS instance.
  • Enter your MySQL username: Enter the username used to connect to the database and press the Enter key. In this example, root is entered.
  • Enter your MySQL password: Enter the password used to connect to the database and press the Enter key.

Note: The password used to connect to the database is the password that you set in Step 3.

  • Enter your database name: Enter the name of the database created for Ghost. Enter ghost_data and then press the Enter key.

Note: The name of the database is the name that you set in Step 3. In the example, the name is ghost_data.

Configure other parameters as instructed based on actual scenarios. After the configuration is complete, the access address for the Ghost administrator is displayed in the lower part of the page. In this example: http://47.98.XX.XX/ghost is displayed.

4.  Test the access to the Ghost site.

Perform the following operations to access the frontend homepage or the backend management page of Ghost:

a) Front homepage

On your Windows computer or a Windows computer that has Internet connectivity, open a browser and enter the <Public IP address of the ECS instance> in the address bar to access the frontend homepage of Ghost.

2

Note: If Error Code 502 occurs, check whether an exception occurs on the firewall of the ECS instance. You can disable the firewall.

b) Background management page

On your Windows computer or a Windows computer that has Internet connectivity, open a browser and enter <Public IP address of the ECS instance>/ghost in the address bar to access the backend management page of Ghost.

The first time you access the backend management page of Ghost, follow the instructions to complete the configurations of Ghost.

3

Operations on Domain Names

If you want to build a website but do not have your own domain name, purchase a domain name. After you purchase a domain name, If your website is deployed on an ECS instance within the Chinese mainland, apply for an Internet Content Provider (ICP) filing for the domain name and resolve the domain name to the public IP address of the ECS instance. Perform the following operations:

• Purchase a domain name

You can specify a unique domain name for your website. This allows users to visit your website by using an easily identifiable domain name instead of a complex IP address. We recommend that you purchase a domain name from Alibaba Cloud. For more information, see Register a domain name on Alibaba Cloud.

• Apply for an ICP filing for the domain name

Apply for an ICP filing for the domain name that is associated with a website hosted on an ECS instance within the Chinese mainland. Your website cannot provide services until you obtain an ICP filing number for the domain name.

• Resolve the domain name

Use Alibaba Cloud DNS to resolve the domain name to the IP address of the ECS instance on which the website is deployed. This way, users can visit your website by using the domain name. For more information, see Get Started with Alibaba Cloud DNS.

0 1 0
Share on

Alibaba Cloud Community

904 posts | 201 followers

You may also like

Comments

Alibaba Cloud Community

904 posts | 201 followers

Related Products