Ghost is a free, open-source blogging platform that is developed based on Node.js to simplify the process of writing and publishing blogs. This topic 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 topic is suitable for 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 service capacity based on your business needs. Examples:
Scale up the vCPUs and memory of a single ECS instance to improve the processing capacity 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 the 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.
Prerequisites
An ECS instance that uses the following configurations is created:
Operating system: Ubuntu 16.04, 18.04, 20.04, or 22.04.
NoteIn this topic, 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
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.
Connect to the ECS instance.
For more information, see Connect to a Linux instance by using a password or key.
Run the following commands to create a user.
In this example, the
test
user is created.adduser test
When the
New password:
andRetype 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 theEnter
key.When the
Enter the new value, or press ENTER for the default
message appears, press theEnter
key to accept the default value. Alternatively, configure Full Name, Room Number, Work Phone, Home Phone, and Other based on actual scenarios.When the
Is the information correct? [Y/n]
message appears, enterY
to confirm the information and press theEnter
key to complete the configuration.
The following code demonstrates 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
Run the following command to add the new user to a group:
usermod -a -G sudo test
Run the following command to switch to the
test
user:su - test
Step 2: Install NGINX
Before you can install Ghost, install NGINX to use as an HTTP server.
Run the following commands in sequence to update the Linux operating system and software packages:
sudo apt-get update sudo apt-get upgrade -y
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)
NoteIn 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.
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))
Run one of the following commands based on the Ubuntu version to connect to MySQL.
Ubuntu 18.04, 20.04, or 22.04
sudo mysql
Ubuntu 16.04
mysql -u root -p
Run the following command to create a database for Ghost.
In this example, a database named ghost_data is created.
CREATE DATABASE ghost_data;
(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';
Run the following command to exit MySQL:
exit
Step 4: Install Node.js
Before you can install Ghost, install Node.js that is required for Ghost.
Run the following command to download the Node.js installation repository:
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash
Run the following command to install Node.js:
sudo apt-get install -y nodejs
Run the following command to check the version of Node.js:
node -v
A command output similar to the following one is returned:
test@iZbp1g2d4dpki2mf63b****:~$ node -v v16.20.1
Step 5: Install Ghost
Run the following command to install Ghost-CLI that is used to configure Ghost:
sudo npm install ghost-cli@latest -g
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
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.
Description of the parameters:
Enter your blog URL: Enter a resolved domain name of Ghost. Example:
http://exapmle.com
. If you do not have a resolved domain name, enter the public IP address of the ECS instance on which to install Ghost. 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.NoteThe 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 and press the
Enter
key. In this example,ghost_data
is entered.NoteThe 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.
Test the connection to the Ghost site.
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 has Internet connectivity, open a browser and enter <Public IP address of the ECS instance> in the address bar to access the frontend homepage of Ghost.
NoteIf Error Code 502 is returned, check whether an exception occurs on the firewall of the ECS instance. You can disable the firewall.
Backend 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.
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.