Explains how to use Hexo+ GitSubPages to create your own personal blog. After using it for a period of time, I found that the access speed was slow. Moreover, I also purchased a cloud server when Tencent Cloud was doing activities some time ago, so I migrated my personal blog to Tencent Cloud. It doesn’t have to be Tencent Cloud, but hopefully with this article, you can deploy your blog on GithubPages to any cloud server.

Again, to fully understand the purpose, I consulted a number of articles, mostly following the instructions line by line to configure the deployment, and used the pagoda panel in the process. Later, because the original server expired, had to redeploy again. Because I didn’t understand it thoroughly, I had to find the article “Play Tencent Cloud” in the Hexo blog to deploy Tencent Cloud to follow the instructions to configure it again and again. But this time, after the configuration, I concluded that having figured out the steps and the purpose of each step, deploying HEXO to the server was not that complicated, and that many of the first configuration steps were unnecessary.

Reading guide

The environment

  • CentOS 7.6 64

The configuration steps

  • The server configures and installs Git repository hosting

    • Install the dependencies required for Git compilation
    • Install git
    • Create a Git User
    • Configure the RSA public key
  • GithubPages as Web server -> installs and configures the Web service of the Nginx cloud server

    • The site directory is created in the cloud service
    • Install and configure NGINX

      • The cloud server is installed with NGINX
      • Configure Nginx
      • Restart the NGINX service
    • Git repository configuration

      • Set up a Git repository and change permissions
      • Synchronize the site root (configure git hook)
      • Modify the permissions
  • Domain resolution to GitHubPages-> Domain resolution to cloud server IP

    Modify domain name resolution

  • Hexo configuration pushed to GitHub repository ->Hexo configuration pushed to cloud server Git repository

    Modify the HEXO configuration

  • test

First of all, I will explain all the steps step by step. At the end of the article, I will integrate these command steps so that you can follow the configuration instructions after understanding. Hopefully, this breakdown and integration has given you a thorough understanding of how to deploy Hexo to a cloud server.

preparation

First of all, you need a cloud server, Tencent cloud, Ali cloud, Jingdong cloud no matter what cloud, what cloud cheap with what cloud. For students, all major platforms offer discounts. If you can’t buy discounted cloud products, you can talk about me privately (not advertising, because I didn’t buy it at that time because it was expensive, and individual users were always intimidating to thousands of people, and I didn’t know the channel until later).

Now that you have built a Blog based on Hexo+ GitSubPages based on my previous article [thoroughly understand how to build a personal Blog using Hexo+ GitSubPages], it is time to start the migration.

The migration work

The overall train of thought

The original use of GithubPages as the Web server for the blog is now replaced by its own cloud server, so you only need to implement the relevant functions provided by the original GithubPages on the cloud server. Recall that GitHub was used to host resources and files related to blogs, so the server needed to have Git capabilities. Using GithubPages as a Web server requires the cloud service to have Web-related services; The original GithubPages resolved the domain name and jumped to the address of GithubPages through the domain name configuration. Now it has been moved to the cloud server. The cloud server has its own IP address, so it must also modify the original domain name resolution and do the domain name related configuration in the server. Finally, Hexo’s push address was configured to be a repository on GitHub, so we’ll have to change the push address here as well

All the Hexo work is done locally to convert md files into HTML pre-files, so there is no need to pre-install HTML. So in summary, at a glance, the following work is needed:

  • GitHub code hosting services -> server install git configuration git repository hosting related services
  • GithubPages as Web server -> installs and configures the Web service of the Nginx cloud server
  • Domain resolution to GitHubPages-> Domain resolution to cloud server IP
  • Hexo configuration pushed to GitHub repository ->Hexo configuration pushed to cloud server Git repository

The server configures and installs Git repository hosting

We used to use GitHubPages to upload and manage our Hexo-related files. Now on the cloud platform, of course, we need a tool to host our blog files similar to code hosting. Here we need to install Git first. If you already have Git tools on your server, you can skip this step. If the Git version is too low, it’s also best to install the latest version.

Install the dependencies required for Git compilation

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install  gcc perl-ExtUtils-MakeMaker

These two commands come up a little muddled, are what ah, anyway I have started is a keyboard shuttle, configuration finished back to decompose understanding. These are just a bunch of libraries that you need to call to do your Git work. Here’s what each dependency package does. You can start with the following and come back to it later.

  • curl-devel

    cURL is a tool for getting files from FTP, HTTP, Gopher, Telnet, and


    Dict servers, using any of the supported protocols. The curl-devel


    package includes files needed for developing applications which can


    use cURL’s capabilities internally.

    Under translation is roughly: cURL package is a from the FTP/HTTP/Gopher/Telent/Dic server access file tools, this tool use all any supported protocols. The curl-devel package integrates all the files that you use to develop your application using the curl package. If you do not install this dependency, you may not be able to install (lib)curl-devel when compiling git, causing problems with “not finding remote helpers for ‘HTTPS'” during git clone time.

  • expat-devel

    a stream-oriented XML parser library written in C.


    Expat excels with files too large to fit RAM, and where performance and flexibility are crucial.

    A library of stream-oriented XML parsers written in C. Expat is good at handling files that are too large to fit in memory, where performance and flexibility are critical.

  • gettext-devel

    Specifically, the GNU gettext utilities are a set of tools that provides a framework to help other GNU packages produce multi-lingual messages. These tools include a set of conventions about how programs should be written to support message catalogs, a directory and file naming organization for the message catalogs themselves, a runtime library supporting the retrieval of translated messages, and a few stand-alone programs to massage in various ways the sets of translatable strings, or already translated strings.

    Specifically, the GNU gettext utility is a set of tools that provide a framework to help other GNU packages generate multilingual messages. These tools include a set of conventions about how programs should be written to support the message directory, the named organization of directories and files that organize the message directory itself, a runtime library that supports the translation of retrieval information, and a number of independent programs that massage collections of translatable strings in various ways, or strings that have been translated.

  • openssl-devel

    This literally means the OpenSSL related library

  • zlib-devel

    The zlib-devel package contains the header files and libraries needed to develop programs that use the zlib compression and decompression library.

  • gcc

    GCC-related packages

  • perl-ExtUtils-MakeMaker

    Extutils ::MakeMaker module, which is the module used to create makefiles.

    Obviously the latter two are because if you don’t have GCC-related tools installed on your cloud server, use them to install C compiler tools because Git is written in C.

Install git

Now that you have the dependencies you need for Git compilation installed, start installing Git.

  • If you have installed a lower version of Git, you first need to uninstall the original Git

    yum remove git
  • To check out the latest version of Git, go to the Git official website and check out the latest version number. Here it is 2.31.0

  • Go to your Git installation directory and select /usr/local/src

    CD /usr/local/ SRC //
  • Download git

    Wget HTTP: / / https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.0.tar.gz / / download link

    Note that the version number is replaced with the version number you want to download

  • Unpack the

    Tar-zxvf git-2.18.4.tar.gz // Unzip it

    It’s always hard to remember the meaning of a few parameters to tar, so just to review

    • -z or –gzip or –ungzip process the backup files through the gzip directive.
    • -x or –extract or –get Restores files from backup files
    • -v or –verbose shows the execution of the instruction
    • -f< backup file > or –file=< backup file > specifies the backup file.
  • Install and compile

    // make prefix=/usr/local/git install // make prefix=/usr/local/git install // make prefix=/usr/local/git install // The path

    All is the target specified in the makefile. If make does not add all, the first target in the makefile will be executed by default. This is the difference. However, in most makefiles, ALL will be the first compile target. If this is the case, then it will be the same whether ALL is added or not. Therefore, the actual result of execution depends on how the makefile is written and whether ALL is the first compile target.

  • Edit and configure the Git path to your environment configuration file

    $PATH = /usr/local/git/bin // export PATH= /usr/local/git/bin // source /etc/profile

Create a Git User

You don’t normally use root to do all the work on a cloud server, so when you upload a file to a cloud server using Hexo, you need to create a Git user and change the permissions for that operation.

  • Create a new git user

    Adduser git // passwd git // set password to 'git' where git is replaced with the password to be set
  • Add the newly created Git user to the sudo group

    chmod 740 /etc/sudoers
    vim /etc/sudoers

Chmod is a change to file permissions, 740 for each owner, group, and other group permissions.

The user’s group has permissions of 4, and the other groups have permissions of 0. So what does 7, 4, 0 mean?

A file has read, write, and execute privileges, i.e. R, W, and X. The corresponding permissions are 4, 2, and 1 (binary), so read permissions are 4, write permissions are 2, and execute permissions are 1. A user or group has privileges that are the sum of these three operations:

– To set the RWX (read-write run) permission at the same time, set the permission bit to 4 + 2 + 1 = 7

– To set the rw- (read-write not runnable) permission at the same time, set the permission bit to 4 + 2 = 6

– To set R-x (Readable, Runable, Not Writable) permissions at the same time, set the permissions bit to 4 +1 = 5

Chmod 740 /etc/sudoers = “read-write” for files, “writable” for groups, and “unreadable, unwritable” for other groups. The simple idea is to advance the current user because the next step is to modify this file.

The /etc/sudoers file manages users in the sudo group. This file is edited here to add Git users to the sudo group. You will no longer need to use sudo to type your password

Add after the following:

## Allow root to run any commands anywhere root ALL=(ALL) ALL

The first ALL indicates that sudo is allowed to be accessed from any terminal or machine

The second (ALL) indicates that the sudo command is allowed to be executed as any user

The third ALL indicates that ALL commands can be executed as root

  • Modify permissions, that is, reduce the current user’s permissions to only read the file, other users can not read and write to modify this file.

    chmod 400 /etc/sudoers

Configure the RSA public key

  • Create the RSA secret key locally, note that this is a local operation, not a remote server

    ssh-keygen -t rsa

    If you’ve already created the public key for RSA, use the old RSA public key that you previously configured on GitHub

    The default location for the RSA public key is ~/.ssh

  • Copy the contents of the id_rsa.pub file to the authorized_keys file of the remote server

    su git
    mkdir ~/.ssh
    vim ~/.ssh/authorized_keys

    Note that the path here is ~, which is the current user’s user folder, because only git can access the RSA public key

  • Modify the permissions

    cd ~
    chmod 600 .ssh/authorized_keys
    chmod 700 .ssh

    Here the reader is asked to think about what the permissions of the current file change with each command jump. Welcome to leave a message.

  • Test the Git service locally

    Now that our git service has been configured successfully, let’s test whether the git service can run successfully. Run locally:

    Ssh-v git@SERVER //@ is the public IP of your own server. If no failed message appears, it indicates success

GithubPages as Web server -> installs and configures the Web service of the Nginx cloud server

The site directory is created in the cloud service

Mkdir = /home/hexo // : /home/hexo // : /home/hexo // : /home/hexo

Chown git:git -r /home/hexo The command used to set the owner of the file and the associated group of the file. Set the owner of all files in /home/hexo and its subdirectories to Git, and the user of the group to the Git group.

-r: Handles all files in the specified directory and its subdirectories

Install and configure NGINX

  • The cloud server is installed with NGINX

    Yum install -y nginx // Systemctl start nginx. Service // Start nginx

    Yum install -y = “Is this OK[y/d/N]

  • Configure Nginx

    Check the location of the nginx.conf configuration file

    /etc/nginx/nginx.conf = /etc/nginx/nginx.conf

    Modifying configuration files

    /etc/nginx/nginx.conf // Add /home/hexo to /etc/nginx/nginx.conf

    Here root is your web root, and here it’s set to the root of our blog site

  • Restart the NGINX service

    systemctl restart nginx.service

Git repositories configure Git hooks

Use the Hexo command to push locally not directly to the root of your site, but to Git’s repository. Because the Git repository is only used to push updates to files and the root directory on the Web has a different function, it cannot be the same. First, you need to create a new folder for your Git repository and use Git’s Git Hook function to synchronize files pushed to your Git repository to the Web root of /home/hexo.

  • Set up a Git repository and change permissions

    su root
    cd /home/git
    git init --bare blog.git
    chown git:git -R blog.git

    Git init –bare creates a bare library with only one.git directory in the working directory. What Is a Bare Git Repository? What is a bare Git Repository? .

  • Synchronize the site root (configure git hook)

    Open the blog. Git /hooks/post-receive file and fill in the following:

    Git /hooks/post-receive // /bin/sh git --work-tree=/home/hexo --git-dir=/home/git/blog.git checkout -f

    Use post-receive in Git hooks to implement the action after the code is committed. Assign the repository to a –work-tree and checkout –force

  • Modify the permissions

    chmod +x /home/git/blog.git/hooks/post-receive

    The previous chmod instructions are numeric permissions, here + X is simply to give execution permissions

Domain resolution to GitHubPages-> Domain resolution to cloud server IP

The first step is to configure the server nginx to add its own domain name to its configuration file. How to find this configuration file refer to the previous chapter section

  • Modify the domain name information in the Nginx configuration file

    /etc/nginx/nginx.conf /etc/nginx.conf /etc/nginx.conf /etc/nginx.conf /etc/nginx.conf /etc/nginx.conf
  • Modify the DNS resolution IP in your own DNS resolution console and modify the A record

I have used the pagoda panel before. If you are interested, you can try it. The visualization operation is also great.

Hexo configuration pushed to GitHub repository ->Hexo configuration pushed to cloud server Git repository

  • Modify the repo after deploy in the _config.yml file in the local Hexo directory

    Git @ SERVER: / home/git/blog. Git / / @ after public IP for the cloud SERVER

    Blog. git is your push repository directory

  • Deploy it and test it

    hexo g

    Nice! Your Hexo personal Blog has been successfully deployed to your personal cloud server!

Configuration Command Guide

Here is a summary of all the commands, according to the following steps of the guidelines, you can complete the deployment of personal Blog on the cloud server, easy reference:

  • Install the dependencies required for Git compilation

    yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
    yum install  gcc perl-ExtUtils-MakeMaker
  • To install Git, if you have installed a lower version of Git, you first need to uninstall the original Git

    yum remove git
  • Go to your Git installation directory and select /usr/local/src

    CD /usr/local/ SRC //
  • Download git

    Wget HTTP: / / https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.0.tar.gz / / download link
  • Unpack the

    Tar-zxvf git-2.18.4.tar.gz // Unzip it
  • Install and compile

    // make prefix=/usr/local/git install // make prefix=/usr/local/git install // make prefix=/usr/local/git install // The path
  • Edit and configure the Git path to your environment configuration file

    $PATH = /usr/local/git/bin // export PATH= /usr/local/git/bin // source /etc/profile
  • Create a new git user

    Adduser git // passwd git // set password to 'git' where git is replaced with the password to be set
  • Add the newly created Git user to the sudo group

    chmod 740 /etc/sudoers
    vim /etc/sudoers
  • Add after the following:

    ## Allow root to run any commands anywhere
    root    ALL=(ALL)       ALL
    --在这里添加----
    git ALL=(ALL) ALL
  • Modify the permissions

    chmod 400 /etc/sudoers
  • Create the RSA secret key locally, note that this is a local operation, not a remote server

    ssh-keygen -t rsa
  • Copy the contents of the id_rsa.pub file to the authorized_keys file of the remote server

    su git
    mkdir ~/.ssh
    vim ~/.ssh/authorized_keys
  • Modify the permissions

    cd ~
    chmod 600 .ssh/authorized_keys
    chmod 700 .ssh
  • Test the Git service locally

    Ssh-v git@SERVER //@ is the public IP of your own server. If no failed message appears, it indicates success
  • The site directory is created in the cloud service

    Mkdir = /home/hexo // : /home/hexo // : /home/hexo // : /home/hexo
  • The cloud server is installed with NGINX

    Yum install -y nginx // Systemctl start nginx. Service // Start nginx
  • Check the location of the nginx.conf configuration file

    /etc/nginx/nginx.conf = /etc/nginx/nginx.conf
  • Modifying configuration files

    /etc/nginx/nginx.conf // Add /home/hexo to /etc/nginx/nginx.conf
  • Restart the NGINX service

    systemctl restart nginx.service
  • Set up a Git repository and change permissions

    su root
    cd /home/git
    git init --bare blog.git
    chown git:git -R blog.git
  • Open the blog. Git /hooks/post-receive file and fill in the following contents

    Git /hooks/post-receive // /bin/sh git --work-tree=/home/hexo --git-dir=/home/git/blog.git checkout -f
  • Modify the permissions

    chmod +x /home/git/blog.git/hooks/post-receive
  • Modify the domain name information in the Nginx configuration file

    /etc/nginx/nginx.conf /etc/nginx.conf /etc/nginx.conf /etc/nginx.conf /etc/nginx.conf /etc/nginx.conf
  • Modify the DNS resolution IP in your own DNS resolution console and modify the A record
  • Modify the repo after deploy in the _config.yml file in the local Hexo directory

    Git @ SERVER: / home/git/blog. Git / / @ after public IP for the cloud SERVER
  • Deploy it and test it

    hexo g

Common mistakes

The following error occurred during the final execution of hexo g:

Bash: git-receive-pack: command Fatal: Could not read from remote repository: fatal

The git directory on the remote server is /usr/local/src/git, not the default directory, so create the link file:

 ln -s /usr/local/src/git/bin/git-receive-pack /usr/bin/git-receive-pack

No other problems have been encountered so far. If you have any other problems, please feel free to comment.

The resources

  • 【 Play Tencent Cloud 】Hexo Blog is deployed to Tencent Cloud
  • Linux to get the latest version of Git and compile and install
  • SLC5X: Development Libraries: curl-devel
  • Libexpat git repository
  • Gettext introduction
  • ExtUtils::MakeMaker
  • Linux the tar command
  • Learn one command every day: sudo to manage Linux permissions
  • Linux chown command
  • Git uses post-receive to automate deployments
  • Linux chmod command
  • git-receive-pack: command not found