Help Center/ Elastic Cloud Server/ Best Practices/ Setting Up a Website/ Manually Deploying a Ghost Blog (Ubuntu 20.04)
Updated on 2024-07-31 GMT+08:00

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.

  1. 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
    1. In the New password: and Retype new password: lines, enter and confirm the user password (not displayed by default) as prompted, and press Enter.
    2. 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.
    3. In the Is the information correct? [Y/n] line, press Y to confirm the information and press Enter to complete the settings.
  2. Run the following command to add the newly created user to the user group:

    usermod -aG sudo user

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

  1. Run the following commands to update the Linux OS 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

  3. Run the following command to check the Nginx version:

    nginx -v

    The following information is displayed:

    nginx version: nginx/1.18.0 (Ubuntu)
  4. (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'

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

  1. Run the following command to install MySQL:

    sudo apt-get install -y mysql-server

  2. Run the following command to check the MySQL version:

    mysql -V

    The following information is displayed:

    mysql  Ver 8.0.37-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
  3. Run the following command to access MySQL:

    sudo mysql

  4. Create a database for Ghost. The following uses ghost_data as an example.

    CREATE DATABASE ghost_data;

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

  6. Run the following command to reload the privilege tables of MySQL to check that the change takes effect:

    FLUSH PRIVILEGES;

  7. Run the following command to exit MySQL:

    exit

Installing Node.js

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

  2. Run the following commands to view the versions of Node.js and Node Package Manager (npm), respectively:

    node -v

    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.

  1. Run the following command to install Ghost-CLI:

    sudo npm install ghost-cli@latest -g

  2. Create a folder named ghost under /var/www/.

    sudo mkdir -p /var/www/ghost

    If ghost is created under /root, Ghost cannot work properly.

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

  4. Run the following command to switch to the created folder:

    cd /var/www/ghost

  5. Run the following command to install Ghost using Ghost-CLI:
    ghost install

    If a message is displayed indicating that the node version does not match, obtain the required version on the official website of Node.js and reinstall Ghost.

    https://nodejs.org/en/download/

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