hexo-to-your-server

Take you through the various potholes and deploy the Hexo blog to your own server at once

Finish result: Click to view personal website

A, start

Configure the local Node environment

  1. Download node from the official website and use NVM if possible

  2. Remember to change the installation directory to another disk, here I specifically in D: programming\nodejs

Open CMD to check node installation

node -v
npm -v
Copy the code
  1. Configuring the Global Environment

Go to the installation directory, create folders node_global and node_cache, and run the commands

npm config set prefix "D:\programming\nodejs\node_global"
npm config set cache "D:\programming\nodejs\node_cache"
Copy the code

Environment configuration: Add environment variables NODE_PATH and add Path, both with values D:\programming\nodejs\node_global

  1. The installationhexo-cli
npm i hexo-cli -g
hexo
Copy the code

Congratulations on your successful global module call if the following is displayed

  1. If a command is not found, or not executable, don’t worry! First carefully repeat 3-4 steps, generally can be solved, if it is really not solved, look back

  2. To initialize the file anywhere, run the following command:

mkdir hexo-blog
cd hexo-blog && npm init -y
Copy the code

Now there are three solutions, one of them

  • Method 1: Check whether the global directory is validhexoModule, execute the following command:
D:\programming\nodejs\node_global\hexo
Copy the code
  • Method 2: If you find it troublesome to add prefixes each time, uselinkCommand link
npm link hexo
Copy the code

Create a new script in package.json as follows

npm run hexo
Copy the code

  • Fa3: You can also go directly to thehexo-blogIn the download
NPM I hexo-cli NPM run hexoCopy the code

Initialize thehexoproject

  1. If you followed step 4 in the previous section, thehexo-blogFile initialization
hexo init myblog && cd myblog
npm i
Copy the code
  1. Download the theme
git clone https://github.com/iissnan/hexo-theme-next themes/next
Copy the code

Set the theme property in the local configuration file

  1. Local implementationhexoProject, addstartThe script
npm start
Copy the code

Check it out at http://localhost:4000

gitEnvironment set up

  1. Git installation: download from the official website

  2. To generate SSH authentication, run the following command

git config --global user.name "yourname"
git config --global user.email [email protected]
ssh-keygen -t rsa -C "[email protected]"
git config --global core.autocrlf false// Disable automatic conversion, this does not set the warning for later upload, as followsCopy the code

The last SSH authentication obtained is in C:\Users\ yourName \.ssh


3. Server configuration

Set up the remoteGitThe private library

  1. Log in to the remote server using Xshell 5 is recommended

  2. Install git

Git --version Yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel yum install -y gitCopy the code
  1. Create users and configure their repositories
Useradd git passwd git // set the password su git //cd/home/git/mkdir -p projects/blog // the actual directory where the project exists mkdir repos &&cdGit init --bare blog. Git // create a bare repositorycdBlogo.git /hooks vi post-receive // create the hook functionCopy the code
#! /bin/sh
git --work-tree=/home/git/projects/blog --git-dir=/home/git/repos/blog.git checkout -f
Copy the code

Modify the permission after the configuration is complete

chmod +x post-receive
exitChown -r git:git /home/git/repos/blog.git // Add permissionCopy the code
  1. testGit repositoryIf available, find another blank folder
git clone git@server_ip:/home/git/repos/blog.git
Copy the code

If you can pull down the empty git repository, you have successfully set up the git repository

  1. To establishsshTrust relationship, inThe local computer
SSH - copy - id - I C: / Users/yourname /. SSH/id_rsa pub git @ server_ip SSH git @ server_ip / / test can log inCopy the code

Note: SSH login git users do not need a password! Otherwise, an error occurs. Repeat Steps 3-5 carefully

  1. For security reasons, disable the git user’s shell login permission, so that only git clone, git push, etc
Cat /etc/shell// Check whether git-shell is included in the login modewhichGit-shell // Check whether vi /etc/shells are installed add the steps displayed in /usr/bin/git-shellCopy the code

Example Change the permission of /etc/passwd

/ / the original git: x: 1000-1000: : / home/git: / bin/bash / / modified to git: x: 1000-1000:,,,, / home/git: / usr/bin/git - shellCopy the code

Set upnginxThe server

  1. Download and Installnginx
cd /usr/localhttp://nginx.org/download/nginx-1.15.2.tar.gz/SRC wget tar XZVF nginx - 1.15.2. Tar. GzcdNginx-1.15.2./ nginx-1.15.2./configure // ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
make && make install
alias nginx='/usr/local/nginx/sbin/nginx'// Alias for nginxCopy the code
  1. configurationnginxfile

Check whether the installation is successful

Nginx // come directly! View server_IP in the browser. The default is port 80Copy the code

Modifying a Configuration File

nginx -s// Stop nginx firstcd /usr/local/nginx/conf vi nginx.conf: /nginx/conf: /nginx/conf: /nginx/conf-s reload
Copy the code

Four, publish,

Now that we have the local and server environments all set up, we can now link using the Hexo configuration file

configuration_config.ymlfile

  1. Edit the deploy attribute of _config.yml

  1. Add the NPM script to package.json
"scripts": {
  "deploy": "hexo clean && hexo g -d",
  "start": "hexo clean && hexo g && hexo s"
},
Copy the code
  1. The link! This is used for local debuggingnpm start, debugging good upload to the server, zizi ~ fast through your server IP access it
npm run deploy
Copy the code

Five, the last word

I front-end novice one, there are mistakes welcome correction

Affidavit personal website, build station initial stage, welcome your presence ~

If you like, please give me a ★ oh

6. Reference links

  • The most detailed Hexo blog setup tutorial ever

  • Deploy the Hexo blog to the server with Git

  • Windows NPM -g global installation command could not be found

  • Hexo sets the theme and Next theme personality

  • Use Git hooks to automatically deploy Hexo to personal VPS

  • Ssh-copy-id establishes trust for you

  • Git Server – Allows Git users to log in using SSH

  • Nginx source code installation and simple configuration