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 topic describes how to deploy the Ghost blogging platform on an Elastic Compute Service (ECS) instance that runs Ubuntu 20.04.

Prerequisites

  • An ECS instance is created. For more information, see Create an instance by using the wizard.
    In this topic, an ECS instance with the following configurations is used. We recommend that you use the same operating system version as that used in the example to prevent command errors caused by operating system version issues.
    • Instance type: ecs.c6.large
    • Operating system: Ubuntu 20.04 public image
    • Network type: Virtual Private Cloud (VPC)
    • IP address: public IP address
  • An inbound rule is added to a security group of the ECS instance to allow traffic on ports 22, 80, 443, and 2368. For more information, see Add a security group rule.

Background information

You can build the Ghost blogging platform in development or production mode. The first time you build the Ghost blogging platform, we recommend that you use the development mode for easy debugging. The procedure described in this topic is applicable to individual users who are new to using Alibaba Cloud to build websites.

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 an Server Load Balancer (SLB) instance and use Alibaba Cloud SLB to load-balance the traffic to these instances.
  • Use Alibaba Cloud Auto Scaling to automatically increase or decrease the number of ECS instances.
  • Use Object Storage Service (OSS) buckets to store large volumes of data such as static web pages, pictures, and videos.

Step 1: Create a user

Ghost recommends not to use the root user to build the Ghost blogging platform. You must create a user and grant permissions to it.

  1. Connect to the instance.
    For more information, see Connection methods.
  2. Run the following commands to create a user.
    In this example, the test user is created.
    adduser test
    1. When the New password: and Retype new password: messages appear, enter and confirm the password. By default, the characters of the password are hidden. After you confirm the password, press the Enter key.
    2. When the Enter the new value, or press ENTER for the default message appears, press the Enter key to use the default value. Alternatively, specify Full Name, Room Number, Work Phone, Home Phone, and Other based on actual scenarios.
    3. When the Is the information correct? [Y/n] message appears, enter the Y key 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 `user' (1000) ...
    Adding new user `user' (1000) with group `test' ...
    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
  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

To deploy the Ghost blogging platform, you must install NGINX to use it as an HTTP server. This step describes how to install NGINX.

  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. Run the following command to 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.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
  2. Run the following command to connect to MySQL:
    sudo mysql
  3. Run the following command to create a database for Ghost.
    In this example, the database named ghost_data is created.
    CREATE DATABASE ghost_data;
  4. Run the following command to set the password for the root user:
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Enter the password of the root user',
  5. Run the following command to exit MySQL:
    \q

Step 4: Install Node.js

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

  1. Run the following command to download the Node.js installation repository:
     curl -sL https://deb.nodesource.com/setup_14.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 check the version of Node.js:
    node -v
    npm -v
    A command output similar to the following one is returned:
    test@iZbp1g2d4dpki2mf63b****:~$ node -v
    v14.19.3
    test@iZbp1g2d4dpki2mf63b****:~$ npm -v
    6.14.17

Step 5: Install Ghost

  1. Run the following command to install Ghost-CLI that is used to configure Ghost:
    sudo npm install ghost-cli@latest -g
  2. Run the following commands in sequence to create the Ghost installation directory and grant permissions on the directory:
    sudo mkdir -p /var/www/ghost
    sudo chown user:user /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
    Specific parameters must be specified while Ghost is being installed, as shown in the following figure.saasaDescription of these parameters:
    • Enter your blog URL: Enter a resolved domain name. Example: http://exapmle.com. In this example, the public IP address http://47.98.XX.XX for testing is entered.
    • Enter your MySQL hostname: Enter the IP address of the instance on which the database is installed. Press the Enter key to use the default value.
    • 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 of the database and press the Enter key.
      Note The password of the database is the password you set in Step 3.
    • Enter your database name: Enter the name of the database created for Ghost and press the Enter key. In this example, ghost_data is entered.
      Note The name of the database is the name 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 connection to the Ghost blogging platform.
    Perform the following operations to access the frontend homepage or the backend management page of Ghost:
    • Frontend homepage
      On your Windows computer or a Windows computer that can access the Internet, open a browser and enter <Public IP address of the ECS instance> in the address bar to access the frontend homepage of Ghost. adada
      Note If the system returns Error Code 502, check whether an exception occurs on the firewall of the instance. You can disable the firewall.
    • Backend management page
      On your Windows computer or a Windows computer that can access the Internet, 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. adad23
      The first time you access the backend management page of Ghost, follow the instructions to complete the configurations of Ghost.

Operations on domain names

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

  • Purchase a domain name

    You can specify a unique domain name for your website. This allows users to visit your website by using a simple 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 generic domain name

  • Apply for an ICP filing for a domain name

    You must apply for an ICP filing for the domain name that is associated with a website hosted on a server within the Chinese mainland. Your website cannot provide services until you obtain the ICP filing number for the domain name.

  • Resolve a domain name

    You must use Alibaba Cloud DNS to resolve the domain name to the IP address of the ECS instance so that users can visit your website by using the domain name. For more information, see Configure the DNS settings for a domain name.