【Fully figured out how to build a personal blog using Hexo+GitHubPagesHexo+GitHubPages explains how to build your own personal blog using Hexo+GitHubPages. After using it for a period of time, I found that the access speed was slow, and 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. Hopefully, with this article, you can deploy your blog originally deployed on GitHubPages to any cloud server.

Again, to get my head around it, I consulted a lot of articles, mostly following the instructions line by line, using the pagoda panel. The original server expired and had to be redeployed. Due to the lack of thorough understanding, Hexo blog deployed Tencent cloud to follow the guidance to configure again and again. However, after the configuration, I found that the steps were clear and the purpose of each step was understood. It was not that complicated to deploy Hexo to the server, and many of the steps in the first configuration were not needed.

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

    • Creating a Git user

    • Configuring an RSA Public Key

  • GitHubPages as Web server -> Installs and configures Web services for Nginx cloud server

    • Create site catalogs in cloud services

    • Install and configure Nginx

      • Cloud server installation Nginx

      • Configure Nginx

      • Restart the Nginx service

    • Git repository configuration

      • Create a Git repository and change permissions

      • Synchronize the website root directory (configure git hook)

      • Modify the permissions

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

    Modifying Domain name Resolution

  • Push Hexo configuration to Github repository -> Push Hexo configuration to Cloud server Git repository

    Modify the Hexo configuration

  • test

At first, 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 them. Hopefully this decomposition and consolidation will give you a thorough understanding of how to deploy Hexo to the cloud.

preparation

First need a cloud server, Tencent cloud, Ali cloud, JINGdong cloud no matter what cloud, what cloud cheap with what cloud. For students, there are discounts on all major platforms. If you can’t buy discounted cloud products, you can chat with me privately (not for advertising, because I didn’t buy them at that time because they were too expensive, and personal users were always thousands of scary, until I knew there were channels).

Now that you’ve built a Blog based on Hexo+GitHubPages based on my previous article, let’s begin our migration.

The migration work

The overall train of thought

GitHubPages originally used as the Web server of the blog is now replaced by its own cloud server, so it only needs to implement the related functions provided by GitHubPages originally on the cloud server. Recall that github used to host blog-related resources and files, so the server had to have Git functionality; Using GitHubPages as a Web server requires the cloud service to have Web-related services; The original GitHubPages resolves the domain name and jumps to the address of GitHubPages through domain name configuration. Now it moves to the cloud server. The cloud server has its own IP address, so it must also modify the original domain name resolution and do domain name related configuration on the server. Finally, Hexo has configured its push address as the repository on GitHub, which must be changed as well

The Hexo work is done locally converting md files to HTML-first files, so there is no need to install HTML-first files. So in summary, at a glance, the following work is needed:

  • Github code hosting services -> Server installation git configure git repository hosting related services
  • GitHubPages as Web server -> Installs and configures Web services for Nginx cloud server
  • Domain name resolution to GitHubPages-> Domain name resolution to cloud server IP
  • Push Hexo configuration to Github repository -> Push Hexo configuration 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, but now we need a tool to do something like code hosting to host our blog files in the cloud, which is where Git is installed first. If you already have git tools on your server, you can skip this step. If the Git version is too low, it is also a good idea 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
Copy the code

These two commands come up a little meng, are what ah, anyway I have begun is a keyboard shuttle, finished configuration back to decompose understanding. Git is a collection of libraries that you need to call to do your job. Here’s how each dependency package works. You can start with the following operations and come back 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 used to develop applications using curl. If you do not install this dependency, compiling Git without installing (lib)curl-devel may result in “no remote helper ‘HTTPS’ found” ** during Git Clone.

  • 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 flow-oriented XML parser library written in C. Expat specializes in handling files that are too big to fit into 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 on how programs should be written to support message directories, the naming organization of directories and files, the message directories themselves, a runtime library that supports translated retrieval information, and some independent programs that massage collections of translatable strings, or strings that have been translated, in various ways.

  • openssl-devel

    This literally means OpenSSL-related libraries

  • 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 used to create makefiles.

    Git is written in C if you don’t have a gCC-related tool installed on your cloud server.

Install git

With the dependencies you need for Git compilation installed, start installing Git.

  • If you have an older version of Git installed, you need to uninstall the original git first

    yum remove git
    Copy the code
  • Git 2.31.0 is the latest version of git

  • Go to the git installation directory and select /usr/local/src

    CD /usr/local/src// Selects a location for saving the fileCopy the code
  • Download git

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

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

  • Unpack the

    Tar -zxvf git-2.18.4.tar.gz // Decompress the packageCopy the code

    Tar: tar: tar: tar: tar: tar

    • -z or –gzip or –ungzip processes backup files with the gzip directive.
    • -x or –extract or –get restores files from backup files
    • -v or –verbose displays the command execution process
    • -f< Backup file > or –file=< Backup file > Specifies the backup file.
  • Install and compile

    Make prefix=/usr/local/git all // compile source code make prefix=/usr/local/git install // install git to /usr/local/git The pathCopy the code

    In the second command, all is a compilation target specified in the makefile. If make does not add all, the first compilation target in the makefile is executed by default. However, in most makefiles, all is used as the first compilation target. If so, it makes no difference whether all is added or not. Therefore, the actual result of execution depends on whether the makefile is written with all as the first compilation target.

  • Edit and configure git’s path to the environment configuration file

    Vim /etc/profile/Add the following information to the end of the file: PATH=$PATH: /usr/local/git/bin/git directory export PATH // Save the file and refresh the environment variable source /etc/profileCopy the code

Creating a Git user

The root user is not normally used for all operations on cloud servers, so when uploading files to cloud servers using Hexo, you need to create a Git user for this operation and change permissions.

  • Creating a Git User

    Passwd git // Set the password to git. Replace git with the password to be setCopy the code
  • Add the newly created Git user to the sudo group

    chmod 740 /etc/sudoers
    vim /etc/sudoers
    Copy the code

Chmod is a modification of file permissions. Each of the 740 characters represents the permissions of the owner, group, and other groups.

The owner has permission 7, the current user’s group has permission 4, and other groups have permission 0.

A file has read, write, and execute permissions, that is, r, w, and x. The corresponding permissions are 4, 2, and 1 (binary). Therefore, the read permission is 4, the write permission is 2, and the execute permission is 1. A user or group has the sum of the 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 but not run) permission at the same time, set the permission bit to 4 + 2 = 6

– To set the r-x (read, run, not write) permission at the same time, set the permission bit to 4 +1 = 5

Chmod 740 /etc/sudoers sets the read/write permissions for files, write permissions for the user group, and unread/write permissions 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 the sudo group of users. Edit this file to add git users to this group. There will be no need to use sudo to enter the password

Add after the following:

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

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 execute as any user

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

  • Modify permission: changes the permission of the current user to only read files. Other users cannot read and modify files.

    chmod 400 /etc/sudoers
    Copy the code

Configuring an RSA Public Key

  • Create the RSA key locally. Note that this operation is local, not remote

    ssh-keygen -t rsa
    Copy the code

    If you have already created an RSA public key, use the same rsa public key you configured on Github

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

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

    su git
    mkdir ~/.ssh
    vim ~/.ssh/authorized_keys
    Copy the code

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

  • Modify the permissions

    cd ~
    chmod 600 .ssh/authorized_keys
    chmod 700 .ssh
    Copy the code

    What is the permission of the current file changed after each hop command? Welcome to leave a message

  • Test the Git service locally

    So far, git service has been configured successfully. Let’s test whether git service can run successfully. Run locally:

    SSH -v git@SERVER //@ Indicates the public IP address of the server. If failed is not displayed, the server succeedsCopy the code

GitHubPages as Web server -> Installs and configures Web services for Nginx cloud server

Create site catalogs in cloud services

Run the following command to create a web site: su root // Run the following command to create a web site: mkdir /home/hexo chown git:git -r /home/hexoCopy the code

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

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

Install and configure Nginx

  • Cloud server installation Nginx

    Yum install -y nginx // install systemctl start nginx.service // Start the serviceCopy the code

    **Is this OK[y/d/N]**

  • Configure Nginx

    Check the location of the nginx.conf configuration file

    Nginx -t /etc/nginx/nginx.conf.Copy the code

    Modifying a Configuration File

    Vim /etc/nginx/nginx.conf // Modify the configuration file // root and add /home/hexoCopy the code

    In this case, root is your web root directory, and this is set to the root directory of our blog site

  • Restart the Nginx service

    systemctl restart nginx.service
    Copy the code

Git repository configures Git hooks

Local push with the Hexo command is not pushed directly to the root of a website, but to git’s repository. Because git repositories are only used to push updates to files that are managed differently than the root directory on the Web, they cannot be the same. The first step is to create a new folder as a Git repository and use Git’s Git hook to synchronize the files pushed to the Git repository to the web root directory /home/hexo.

  • Create a Git repository and change permissions

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

    Git init –bare Creates a bare library with only one. Git directory in the working directory. What is a bare Git repository? .

  • Synchronize the website root directory (configure git hook)

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

    Vim blog.git/hooks/post-receive /bin/sh git --work-tree=/home/hexo --git-dir=/home/git/blog.git checkout -fCopy the code

    Use post-receive in git hooks to implement the actions after the code is committed. Specify a –work-tree for the repository and perform checkout –force

  • Modify the permissions

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

    The chmod command in the previous section is a numerical representation of permission, where +x simply gives permission to execute

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

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

  • Modify the domain name information in the Nginx configuration file

    Vim /etc/nginx/nginx.conf // Modify the configuration file // Add your own domain name to server_nameCopy the code
  • Change the domain name resolution IP address on your OWN DNS resolution console and modify record A

Having used the pagoda panel before, you can try it out if you are interested. The visualization is also great.

Push Hexo configuration to Github repository -> Push Hexo configuration 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 SERVERCopy the code

    Blog.git is your push repository directory

  • Deploy and test it

    hexo g
    Copy the code

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

Configuration Commands

Here is a summary of all the commands, follow the steps below to complete the deployment of personal Blog on the cloud server for 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
    Copy the code
  • Install Git. If you have an older version installed, uninstall the original git first

    yum remove git
    Copy the code
  • Go to the git installation directory and select /usr/local/src

    CD /usr/local/src// Selects a location for saving the fileCopy the code
  • Download git

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

    Tar -zxvf git-2.18.4.tar.gz // Decompress the packageCopy the code
  • Install and compile

    Make prefix=/usr/local/git all // compile source code make prefix=/usr/local/git install // install git to /usr/local/git The pathCopy the code
  • Edit and configure git’s path to the environment configuration file

    Vim /etc/profile/Add the following information to the end of the file: PATH=$PATH: /usr/local/git/bin/git directory export PATH // Save the file and refresh the environment variable source /etc/profileCopy the code
  • Creating a Git User

    Passwd git // Set the password to git. Replace git with the password to be setCopy the code
  • Add the newly created Git user to the sudo group

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

    ## Allow root to run any commands anywhere root ALL=(ALL) ALLCopy the code
  • Modify the permissions

    chmod 400 /etc/sudoers
    Copy the code
  • Create the RSA key locally. Note that this operation is local, not remote

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

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

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

    SSH -v git@SERVER //@ Indicates the public IP address of the server. If failed is not displayed, the server succeedsCopy the code
  • Create site catalogs in cloud services

    Run the following command to create a web site: su root // Run the following command to create a web site: mkdir /home/hexo chown git:git -r /home/hexoCopy the code
  • Cloud server installation Nginx

    Yum install -y nginx // install systemctl start nginx.service // Start the serviceCopy the code
  • Check the location of the nginx.conf configuration file

    Nginx -t /etc/nginx/nginx.confCopy the code
  • Modifying a Configuration File

    Vim /etc/nginx/nginx.conf // Modify the configuration file // root and add /home/hexoCopy the code
  • Restart the Nginx service

    systemctl restart nginx.service
    Copy the code
  • Create a Git repository and change permissions

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

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

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

    Vim /etc/nginx/nginx.conf // Modify the configuration file // Add your own domain name to server_nameCopy the code
  • Change the domain name resolution IP address on your OWN DNS resolution console and modify record A

  • 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 SERVERCopy the code
  • Deploy and test it

    hexo g
    Copy the code

Common mistakes

The following error was encountered when hexo G was finally executed:

Bash: git-receive-pack: not found command fatal: Could not read from remote repositoryCopy the code

/usr/local/src/git is not the default git installation path on the remote server.

 ln -s /usr/local/src/git/bin/git-receive-pack /usr/bin/git-receive-pack
Copy the code

No other problems have been encountered so far. If you have other problems, please comment and exchange.

The resources

  • Hexo blog is deployed to Tencent Cloud
  • Linux Obtain the latest version of Git, compile and install it
  • SLC5X: Development Libraries: curl-devel
  • Libexpat Git repository introduction
  • Gettext introduction
  • ExtUtils::MakeMaker
  • Linux the tar command
  • Learn one command a day: sudo to manage Linux permissions
  • Linux chown command
  • Git uses post-receive to automate deployment
  • Linux chmod command
  • git-receive-pack: command not found