Ghost is a free and 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 22.04 or 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 facilitate debugging. The procedure in this topic is suitable for users who are new to using Alibaba Cloud to set up 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 requirements. 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 distribute 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.
To set up a Ghost site, the following versions are required for Nginx, MySQL, and Node.js:
Nginx: 1.9.5 and later
MySQL: 8.0.x
Node.js: 20.x (recommended) and 18.x
For more information about the version requirement, see Prerequisites.
Prerequisites
An ECS instance that meets the following requirements is created:
The instance is associated with an auto-assigned public IP address or an elastic IP address (EIP). For more information, see Associate or disassociate an EIP.
The instance runs Ubuntu 20.04 or 22.04.
An inbound rule is added to a security group of the ECS instance to open the following ports: 22, 80, 443, and 2368. For more information, see Add a security group rule.
(Optional) Step 1: Create a user
If you specified 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 set up 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 command 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 use the default value. You can also configure the following parameters based on your actual scenarios: Full Name, Room Number, Work Phone, Home Phone, and Other.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
Make sure that your ECS instance is associated with an auto-assigned public IP address or an EIP. For more information, see Associate or disassociate an EIP.
Before you install Ghost, you must install NGINX 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
Run the
nginx -v
command to check the version of NGINX.nginx -v
The following sample command output is returned.
nginx version: nginx/1.18.0 (Ubuntu)
NoteIn this example, NGINX 1.18.0 is installed. The software installation package is not updated regularly. The actual NGINX version that you install may be different.
Step 3: Install MySQL
MySQL is an open source database management system. In most cases, MySQL is installed as part of the Linux, Apache, MySQL, and PHP/Perl/Python (LAMP) 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 MySQL version. The following sample command output indicates that MySQL is installed:test@iZbp1g2d4dpki2mf63b****:~$ mysql -V mysql Ver 8.0.40-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))
Run one of the following commands based on the Ubuntu version to connect to MySQL:
sudo mysql
Run the following command to create a database for Ghost.
In this example, a database named ghost_data is created.
CREATE DATABASE ghost_data;
Run the following command to configure the password of the
root
user:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Enter a password for the root user';
Run the following command to reload the MySQL privilege table to ensure that modifications to the permissions on the database take effect:
FLUSH PRIVILEGES;
Run the following command to exit MySQL:
exit
Step 4: Install Node.js
Ghost supports only Node.js 20.x (recommended) and 18.x. In this example, Node.js 20.x is used.
Run the following command to download the Node.js installation repository:
curl -sL https://deb.nodesource.com/setup_20.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 Node.js version:
node -v
The following sample command output is returned.
test@iZbp1g2d4dpki2mf63b****:~$ node -v v20.18.0
Step 5: Install Ghost
(Optional) Set the node package manager (npm) image repository to the Alibaba Cloud image repository to accelerate the installation of Ghost.
ImportantChanging the npm image repository may affect all subsequent installation procedures of npm packages. We recommend that you run the
npm config set registry https://registry.npmjs.org/
command to restore the default configurations of npm after Ghost is installed.npm config set registry https://registry.npmmirror.com
Run the following command to install Ghost-CLI that is used to configure Ghost:
sudo npm install ghost-cli@latest -g
The command output shown in the following figure indicates that Ghost-CLI is installed.
Run the following commands in sequence to create a directory in which you want 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
Configure the following specific parameters during the Ghost installation process. Configure other parameters as prompted based on actual scenarios.
Description of the parameters:
Enter your blog URL: Enter a resolved domain name of Ghost. Example:
http://example.com
. If you do not have a resolved domain name, enter the public IP address of the ECS instance on which you want 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 use the default value because the MySQL database and Ghost are installed on the same ECS instance.Enter your MySQL username: Enter the username that is used to log on to the database and press the
Enter
key. In this example,root
is entered.Enter your MySQL password: Enter the password that is used to log on to the database and press the
Enter
key.NoteThe password that is used to log on to the database is the password that you specified in Step 3.
Enter your Ghost database name: Enter the name of the database that you 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 specified in Step 3. In this example, the name is
ghost_data
.
After you complete the configurations, 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.
To access the frontend homepage or the backend management page of Ghost, perform the following operations:
Frontend homepage
On your Windows computer or a Windows computer that has Internet access, open a browser and enter http://<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 access, open a browser and enter
http://<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 set up 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 in 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 way, users who want to visit your website can use a domain name that is easy to identify 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 deployed on an ECS instance in the Chinese mainland. Your website can provide services only after 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.