Ghost Blog Website Building Tutorial Part 1 (Introduction and Installation)

This article will describe what Ghost is, which construction method is suitable for you, how to choose a server, and how to build Ghost in the fastest way.

Preface

This article has more words because it is a little more detailed, but the actual operation will not take more than 10 minutes (provided the system network environment is good). Most of the time during the operation, you are actually waiting for installation. Part of the article is based on official document translation, and summarizes some common pitfalls and their solutions.

About Ghost:

Ghost  is a personal blog system designed to simplify the process of personal website publishing and online publishing. The official also provides APIs for developing plug-ins and customizable Handlebars theme template styles.

The official provides a variety of construction methods, including official hosting, third-party hosting and self-hosting (commonly known as self-building)

Ghost was founded by John O'nolan in 2013 as a startup project by some of the best former WordPress employees. The project is still 100% open source, coupled with the official paid hosting business model, it has now developed into a very blogging system.

Compared to WordPress, Ghost focuses more on writing! Since WordPress really has too many things that can be optimized (its advantages are also disadvantages for non-professional users), it feels a bit like being dedicated to optimization instead of writing, so I also switched from WordPress to Ghost.


How to choose a construction method

Not familiar with Linux/ pure newbie

Regarding setup, if you are not very familiar with Linux and don’t have time to learn code and network knowledge.

I recommend you choose hosting. The advantage of this method is that professionals will maintain the server for you, and you only need to focus on updating your own content.

Many people may set up blogs just to have fun, write short articles, and record the beauty around them. You don’t want to spend a lot of money on domain names and servers, and you don’t want to spend too much time maintaining them. Then third-party hosting is your best choice!

 

Ghost official hosting price list, click on the image to jump to the Ghost Pro page

The only drawback is that official hosting prices are generally on the expensive side, starting at as low as $9 per month. However, there are also very cheap third-party hosting (will be discussed later), but the access speed may not be ideal.

Familiar with Linux / Love tinkering

If you have a preliminary understanding of Linux, or just like to do it yourself. Then I recommend you choose self-hosting. The advantage of this method is that it is relatively economical and highly customizable. Of course, if you want to seriously build a blog in the later stage, the cost of domain names and servers will increase slightly.

For those who like to mess around, I recommend using hosting + self-hosting. When working with self-hosted machines, if you accidentally configure the wrong configuration, users will be unable to access it. If you happen to not know how to fix it, you will have to spend time searching for answers, and some VPS merchants do not support one-click system reinstallation on the panel. So a hosted machine is best for tinkering with and then bringing the final version online in a self-hosted server.

Group and server selection

Server type: Ghost supports AMD and ARM! ! ! So on the premise of using Rclone to back up data, Oracle can also fight.

The target group of a website determines whether your VPS line needs to be optimized in mainland China and whether the domain name needs to be registered (the following are just examples of machines that bloggers are currently using/have used in the past, and no guarantee is provided here for merchants, please purchase as needed)

  • If you are a domestically oriented blog, please give priority to domestic machines from major manufacturers such as Alibaba Cloud/Tencent Cloud.

Advantages: Domestic access is faster, and there is no need to worry about being blocked by a wall.

Disadvantages: The domain name needs to go through the registration process, otherwise it cannot be resolved.

If you are too lazy to register, you can choose servers from third-party merchants located in Hong Kong, San Jose, and Frankfurt, or you can go to other merchants to purchase domestically optimized lines such as CN2 GIA/4837/9929.

  • If you don’t consider targeting domestic users, there are many choices for VPS. Rich people can go directly to big companies such as AWS, GCP, and Azure. If you are satisfied, you can choose the merchants with the following prices.

Advantages: No matter how bad the machine is, it won't be much worse when put on Cloudflare, and there is no need to register.

Disadvantages: There is a mixed bag of good and bad, so try to choose big factories and businesses that have been established for many years.

Deployment - Hosting (taking PikaPods as an example)

Preparatory steps

  • Purchase a domain name in advance (optional)
  • An international credit card/US PayPal

A good domain name is conducive to brand promotion. An excellent domain name can allow customers to remember and find you quickly, create brand value and attract repeat visits.

Start building

1. Enter the official website of PikaPods and register an account

2. Click ADD PODS in the upper right corner to create a new container

3. Related configurations

Enter Ghost in the Choose App column, enter the name you want for Pod Name, and just choose any one in the area where the Pod Region server is located...it doesn't look the same.

The system will give you the minimum configuration required. You can modify it according to your own preferences (generally, if the number of visits is not large, there is no need to modify it). Click the green ADD POD to create it with one click.

The hard disk space given here refers to the space occupied by your blog's pictures, text, etc. The space occupied by Ghost itself will not be counted.

Note: The number of CPUs, memory, and hard disk size can be adjusted at will later, but the server area cannot be changed after the container is created! ! !

Update: On September 21st, while I was still writing the tutorial, I received an official email stating that due to low demand for servers in Hong Kong, the Hong Kong server was removed and moved to Los Angeles. (But it will be optimized for Asia)

 

4. Wait for about 20 seconds to complete the creation, click the gear ⚙️ to enter the settings panel

The console will display the current running status and the version of Ghost that is running.

PikaPod will provide a free and customizable third-level domain name for you to use. If you have purchased a domain name, you can also turn on the Custom Domain switch and configure CNAME to achieve the effect of a customized domain name.

 When creating a container, the system will randomly assign a domain name. If you are not satisfied, you can modify it yourself.

The SFTP switch is required when accessing the container, because you only have ownership of the container, but the VPS that created the container is owned by PikaPod, so you cannot use SSH connections like the VPS you usually purchase. Therefore, you need to use SFTP when you need to upload theme files or customize certain configurations.

 After it is turned on, the information required to access the container will be displayed: address, username, port, and password.

You can use FTP tools such as FileZilla to connect, modify and upload files.

https://filezilla-project.org/

5. Click OPEN POD to enter the container to enter your blog homepage.

If you want to enter the administrator backend, you only need to add the domain name to   /Ghost enter the backend, for example: https://yourdomainname/ghost

 

 Initial page preview, you can change other templates after logging in to the backend.

If you want to enter the administrator background, you only need to add /Ghost to the domain name to enter the background, for example: https://your domain name/ghost

The first time you log in to the backend, you need to register administrator information. Please remember your registration email and password.

More tutorials on optimizing Ghost will be released in the next article.

Deployment - own server

Preparatory steps

  • One server, both AMD and ARM architectures are available. (It is recommended to use a new system environment to operate, otherwise there may be some mysterious errors that you don’t know how to fix)
  • One domain name
  • SSH tools, such as Xshell, FinalShell, etc.

Start deployment (take Ubuntu installation as an example)

No need to worry, whether you are using the command line or using Docker to install, you only need to copy and paste to complete the installation!

Ghost Blog is an open source dynamic blog. It cannot be hosted on cloud platforms such as Vercel/Railway/Netfily like static blogs, so we need to prepare a server to run Ghost.

 Official installation method

The official documentation recommends using a server with running memory ≥ 1G and equipped with Ubuntu 16.04 / 18.04 / 20.04 LTS system.

In addition to running based on Node.js (content of this article), Ghost officially also provides Ghost Blog running based on Docker.

It should be noted that in the future, you may also need to customize the theme of your blog, customize RSS, add a table of contents to the article, etc.

  • If you already know Docker and Linux related commands, then I recommend you to use Docker installation (after all, it only takes two lines of commands)
  • Otherwise, please follow the installation method below. Although it is indeed convenient to build Docker with one click, if you don't know much about Docker-related commands, you may not know where to start when you want to perform the above-mentioned operations. The advantage of this method is that you can directly add/delete files through software such as FinalShell, and use modern editors such as VScode and Sublime to edit, instead of entering the container first and then using vim and other commands to edit and add files.

Server settings

This part of the guide will ensure that all prerequisites for installing Ghost-CLI are met.

1. Update software package

Make sure the package list and installed packages are up to date.

# 通过终端/软件连接SSH
ssh root@你的服务器ip

# 更新系统软件包
sudo apt update && apt upgrade -y

Follow any prompts and enter the password you just created in the previous step.

2. Create new user

Open your terminal/SSH tool and log into the server as root:

Note: Using ghost as the username will cause conflicts with Ghost-CLI. You can use any name other than ghost.

# 通过终端连接SSH
ssh root@你的服务器ip

# 创建一个新用户并按照提示操作创建密码,用户名需自行替换(不得使用 ghost 作为用户名)
adduser 用户名

例子:我想使用yummy作为用户名,则输入 adduser yummy,随后就会看见下面的代码。

Adding user `yummy' ...
Adding new group `yummy' (1000) ...
Adding new user `yummy' (1000) with group `yummy' ...
Creating home directory `/home/yummy' ...
Copying files from `/etc/skel' ...

# 看到这行的时候输入你希望设置的密码。(为了防偷窥,输入的密码是隐藏不可见的,输入完毕后回车即可)
New password: 

# 重新输入上一步的密码
Retype new password: 

# 看见这步则提示两次输入的密码相同,创建密码成功
passwd: password updated successfully
Changing the user information for yummy

# 这里可以无脑回车,你也可以自定义
Enter the new value, or press ENTER for the default
        Full Name []: 
        Room Number []: 
        Work Phone []: 
        Home Phone []: 
        Other []: 

# 确认信息输入正确后输入 y 并按下回车
Is the information correct? [Y/n] 

Add sudo permissions to the new user and switch the current identity to this user.

# 赋予用户 sudo 权限
usermod -aG sudo 用户名

# 切换到刚刚创建的新用户
su - 用户名

3. Install NGINX

Ghost needs to use the NGINX service, and the SSL configuration needs to be equipped with NGINX 1.9.5 or higher.

# 安装 NGINX
sudo apt-get install nginx

If ufw is turned on in the system, the firewall needs to allow Nginx HTTP and HTTPS connections.

# 打开防火墙
sudo ufw allow 'Nginx Full'

# 开启成功将得到以下回应
Rules updated
Rules updated (v6)

4. Install MySQL

Next, you need to install MySQL as the database.

# 安装 MySQL
sudo apt-get install mysql-server

After the MySQL installation is complete, you need to reset the database root user password.

# 重置 MySQL root 密码
sudo mysql

# ‘mysql> ’ 字段不用复制
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
mysql> quit;

5. Install Node.js

 

 

Note that Ghost only supports Node.js 14.x and 16.x (it is recommended to install Node 16.x)

# 安装 curl 工具
sudo apt install curl

# 从 NodeSource 添加 Node.js 16 下载源
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash

# 安装 Node.js
sudo apt-get install -y nodejs

The server setup is complete, let’s start installing Ghost-CLI


Install Ghost-CLI

Ghost-CLI is a command line tool that helps you quickly and easily install and configure Ghost for use. It can be installed using npm or yarn.

# 使用 npm 安装 Ghost-CLI
sudo npm install ghost-cli@latest -g

# 安装完成后可能会看到以下提示,这是由于 npm 存在新版本可升级的提示,不是软件报错!这里可以自行选择是否需要升级。
npm notice New minor version of npm available! 8.15.0 -> 8.19.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2
npm notice Run npm install -g [email protected] to update!

# 升级 npm
npm install -g [email protected]

After installation, you can run ghost help at any time to see a list of available commands.


Install Ghost

After completing the server setup and installing Ghost-CLI, we can start installing Ghost itself.

1. Create a directory and give permissions to the folder

# 创建目录: 更改“站点名”为你喜欢的任何名称
sudo mkdir -p /var/www/站点名

# 设置该目录的所有者: 将用户名替换为“服务器设置”步骤中创建的用户名
# 注意区分用户名和站点名!
sudo chown 用户名:用户名 /var/www/站点名

# 设置文件夹权限
sudo chmod 775 /var/www/站点名

# 前往文件夹
cd /var/www/站点名

2. Run the installation process

Now we use the last command line to install Ghost.

# 开始安装 Ghost 本体
ghost install

# 检查系统环境
✔ Checking system Node.js version - found v16.17.0
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Finishing install process

If at this step, the system detects that any of the settings are not correct, it may be because your system environment has been modified previously. In this case, you need to go to Google for answers.

It is recommended to use a freshly installed pure system for installation.

Installation configuration

During the installation process, the CLI will ask some questions about the site configuration.

During the installation process, the content displayed by () in each configuration is the default configuration. If no modification is needed, you can press Enter directly. Otherwise, please enter it yourself and then press Enter!

1. Blog address

# 输入网站要绑定域名的,不可使用IP地址作为域名,会报错!!!
? Enter your blog URL: http://xxx.com 或 https://xxxx.com

给纯小白的贴士:这里不一定非要 .com 网站

If you use HTTPS, Ghost-CLI will offer to set up SSL for you.

2.MySQL host name

This determines where the MySQL database can be accessed from.

  • When MySQL is installed on the same server as Ghost, use localhost (press Enter to use the default).
  • If MySQL is installed on another server, please enter the corresponding host name manually.
# 输入 MySQL 数据库服务器地址、用户名、密码、数据库名称
? Enter your MySQL hostname: localhost

? Enter your Ghost database name: db_ghost
✔ Configuring Ghost
✔ Setting up instance
+ sudo chown -R ghost:ghost /var/www/ghost/content
✔ Setting up "ghost" system user

3.MySQL username/password

  • If you already have a MySQL database, enter your username.
  • Otherwise, enter root followed by the root user's password.
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]

4.Ghost’s database name

  • If you have not created a database yet, you can use the default value directly: db_ghost, and then the system will start to set it up automatically.
  • If you used a non-root MySQL username/password in the previous step, you need to ensure that the database already exists and has the correct permissions.
# 输入数据库名称,这里系统会随机生成一个,直接回车即可。
? Enter your Ghost database name: db_ghost

✔ Configuring Ghost
✔ Setting up instance
+ sudo useradd --system --user-group ghost

# 输入用户密码
? Sudo Password [input is hidden] 

+ sudo chown -R ghost:ghost /var/www/yummy/content
✔ Setting up "ghost" system user

5. Set up Ghost MySQL user (recommended)

If MySQL used root previously, you can let Ghost-CLI automatically create a user belonging to the Ghost database.

# 输入 Y 确定创建
? Do you wish to set up "ghost" mysql user? (Y/n) 

✔ Setting up "ghost" mysql user

6. Automatically set up NGINX? (recommended)

Automatically set up NGINX to make your site accessible externally. You can manually set up NGINX yourself, but why bother yourself?

If this machine already has other websites or needs to use a customized website environment, you need to skip automatically configuring Nginx and SSL certificates.

# 输入 Y 完成自动配置
? Do you wish to set up Nginx? (Y/n)

+ sudo mv /tmp/1230-one/1230.one.conf /etc/nginx/sites-available/1230.one.conf
+ sudo ln -sf /etc/nginx/sites-available/1230.one.conf /etc/nginx/sites-enabled/1230.one.conf
+ sudo nginx -s reload
✔ Setting up Nginx

7. Automatically set up SSL (recommended)

If you entered the address with https as the blog URL in the first step and configured the record correctly (configure the A record at the domain name purchaser)

# SSL证书设置需要一个电子邮件地址,以便在证书有任何问题时(包括在续订期间)随时通知您。
? Enter your email (For SSL Certificate)

Ghost-CLI can automatically set up SSL for you using Let's Encrypt. Alternatively, you can do this later by running "ghost instal ssl" at any time.

8. Set up systemd (recommended)

systemd is the recommended process manager tool to keep Ghost running smoothly. We recommend selecting yes, but you can also set up your own process management.

# 输入 Y 设置 systemd
? Do you wish to set up Systemd? (Y/n)

+ sudo mv /tmp/yummy/ghost_yummy.service /lib/systemd/system/yummy.service
+ sudo systemctl daemon-reload
✔ Setting up Systemd
+ sudo systemctl is-active ghost_yummy

9. Start Ghost

# 输入 Y 启动 Ghost
? Do you want to start Ghost?  (Y/n)
+ sudo systemctl start ghost_yummmy-best
+ sudo systemctl is-enabled ghost_yummmy-best
+ sudo systemctl enable ghost_yummmy-best --quiet
✔ Starting Ghost

Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail

------------------------------------------------------------------------------

# 当显示这条信息时,表示 Ghost 已完成安装流程
Ghost was installed successfully! To complete setup of your publication, visit: https://yummmy.best/ghost/

Site configuration

Open the browser, enter your blog domain name, and you will see the blog homepage‌

 

If you want to enter the administrator background, you only need to add /Ghost to the domain name to enter the background, for example: https://your domain name/ghost

The first time you log in to the backend, you need to register administrator information. Please remember your registration email and password.

More tutorials on optimizing Ghost will be released in the next article.

Supongo que te gusta

Origin blog.csdn.net/weixin_45034594/article/details/132456354
Recomendado
Clasificación