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 CentOS 7.

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 operating system version in the example to prevent command errors caused by operating system version issues.
    • Instance type: ecs.c6.large
    • Operating system: CentOS 7.8 64-bit 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 security group rules.

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

Step 1: Deploy the web environment

This section describes how to deploy the web environment by installing NGINX.

  1. Install NGINX.
    yum -y install nginx
    After you install NGINX, run the nginx -v command to check the version of NGINX.
    Note In this example, NGINX 1.20.1 is installed. The software installation package is updated on a regular basis. The version of NGINX that you install may be different.
  2. Enable NGINX to start on instance startup.
    systemctl enable nginx.service
  3. Start NGINX.
    systemctl start nginx.service
  4. Check the state of NGINX.
    systemctl status nginx.service
    If NGINX is running normally, it is in the Active state. active nginx
    Note 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 NGINX. If NGINX is deployed, the Welcome to nginx! or Welcome to CentOS message appears.

Step 2: Install Ghost

  1. Update the Linux operating system to the latest version.
    yum -y update
  2. Install Node.js.
    Before you install Ghost, install Node.js required for Ghost.
    1. Install the Extra Packages for Enterprise Linux (EPEL) repository.
      yum -y install epel-release
    2. Install Node.js and Node Package Manager (npm).
      yum -y install nodejs npm --enablerepo=epel
    3. Install the version manager for Node.js.
      npm install -g n
    4. Install Node.js of a stable version.
      In this example, Node.js 12.16.3 is installed.
      n 12.16.3
      Note If you have multiple versions of Node.js, run the n command to select Node.js 12.16.3.
    5. Configure environment variables.
      1. Open the configuration file for environment variables.
        vim ~/.bash_profile
      2. Press the I key to enter the edit mode and add the following content to the end of the file:
        export N_PREFIX=/usr/local/bin/node
        export PATH=$N_PREFIX/bin:$PATH
        After you add the preceding content, press the Esc key, enter :wq, and then press the Enter key to save and close the file.
      3. Run the following command to apply the environment variables:
        source ~/.bash_profile
    6. Install the process manager to control Node.js applications.
      The process manager keeps the applications in the running state.
      npm install pm2 -g
    7. Run the following commands in sequence to check the versions of Node.js and npm:
      node -v
      npm -v
      In the following example command output, the Node.js version is 12.16.3 and the npm version is 6.14.4.node npm -v
  3. Install Ghost.
    1. Create a directory to which to install Ghost.
      mkdir -p /var/www/ghost
    2. Run the following commands in sequence to download the Ghost package.
      1. Go to the directory to which to install Ghost.
        cd /var/www/ghost
      2. Download the Ghost package.
        wget https://ghost.org/zip/ghost-latest.zip
      3. Rename the package ghost.zip.
        mv ghost-latest.zip ghost.zip
    3. Decompress the Ghost package.
      Note If the unzip decompression command is not installed in your ECS instance, run the yum -y install unzip command to install it.
      unzip ghost.zip
    4. Install GCC and C++ compilers.
      yum -y install gcc gcc-c++
    5. Use npm to install Ghost.
      npm install -production
      Note Wait until Ghost is installed. If a prompt appears indicating that a vulnerability exists after Ghost is installed, we recommend that you run the npm audit fix command to have the vulnerability automatically fixed.
    6. Run the following command to start Ghost and check whether Ghost is installed:
      npm start
      The following example command output indicates that Ghost is started:
      [2020-04-13 04:00:01] INFO Ghost is running in development...
      [2020-04-13 04:00:01] INFO Listening on: 127.0.0.1:2368
      [2020-04-13 04:00:01] INFO Url configured as: http://localhost:2368/
      [2020-04-13 04:00:01] INFO Ctrl+C to shut down
      [2020-04-13 04:00:01] INFO Ghost boot 2.185s
      After Ghost is started, press Ctrl+C to exit Ghost.
    7. Optional:Modify the config.development.json file (the configuration file of Ghost in development mode) in the /var/www/ghost/core/shared/config/env directory.
      If you already have a domain name for Ghost, you can resolve the domain name to the public IP address of the ECS instance on which Ghost is deployed. Then, perform the following steps to configure the domain name of Ghost. If you do not have a domain name for Ghost, skip this step and use the public IP address of the instance to access Ghost. After you register and resolve a domain name for Ghost, you can perform the following steps to configure the domain name of Ghost. For more information about the operations on domain names, see Operations on domain names.
      1. Open the config.development.json file.
        vi /var/www/ghost/core/shared/config/env/config.development.json
      2. Press the I key to enter the edit mode and set the url parameter to the domain name of Ghost. Domain name configurations
      3. After the configuration is complete, press the Esc key, enter :wq, and then press the Enter key to save and close the file.
  4. Specify NGINX as the reverse proxy for Ghost.
    1. Go to the NGINX configuration directory.
      cd /etc/nginx/conf.d/
    2. Create and open a NGINX configuration file for Ghost.
      vim /etc/nginx/conf.d/ghost.conf
    3. Press the I key to enter the edit mode and add the following content to the ghost.conf file and set server_name to the domain name of Ghost that is used in your actual runtime environment.
      Note If you have not bound a domain name to Ghost, change the value of server_name to localhost.
      upstream ghost {
          server 127.0.0.1:2368;
      }
      server {
          listen      80;
          server_name example.com;
      
          access_log  /var/log/nginx/ghost.access.log;
          error_log   /var/log/nginx/ghost.error.log;
      
          proxy_buffers 16 64k;
          proxy_buffer_size 128k;
      
          location / {
              proxy_pass   http://127.0.0.1:2368;
              proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
              proxy_redirect off;
      
              proxy_set_header    Host            $host;
              proxy_set_header    X-Real-IP       $remote_addr;
              proxy_set_header    X-Forwarded-For $proxy_add_X_forwarded_for;
              proxy_set_header    X-Forwarded-Proto https;
          }
      }
    4. After the configuration is complete, press the Esc key, enter :wq, and then press the Enter key to save and close the file.
    5. Restart NGINX.
      systemctl restart nginx.service
  5. Run the following commands in sequence to go to the directory where Ghost is located and start Ghost:
    cd /var/www/ghost/
    npm start
  6. 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. Frontend homepage
      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. Backend management page
      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 can purchase a domain name first. 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 mainland China, and then resolve the domain name to the public IP address of the ECS instance on which the website is deployed.

  • 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 the domain name

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

  • Resolve the 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.