Feb 27, 2025
Create hexo blog on server
Create hexo static blog on server
Configuration on local client
Install Git
1 | apt install git |
Install Node.js
This will also install npm:
1 | curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - |
Install Hexo
- Install Hexo
1 | npm install -g hexo-cli |
- Initialize Hexo
Run the init command to set up Hexo. This will create a blog folder, which serves as your blog’s root directory. All operations will be carried out in this directory.
1 | hexo init blog |
- Generate Static Pages
1 | cd blog |
- Start the Local Server for Article Preview and Debugging
1 | hexo server |
Open the browser and navigate to http://localhost:4000.
This is for local debugging. Next, we will upload the CSS files to the server and set up the website.
Configuration on server
Install and Configure Git
Open a terminal and SSH into the server:
1 | ssh root@vpsip |
Enter the password to access the VPS. All following steps will be done on the server.
- Install and Create the Git User
1 | apt install git # Install Git |
- Grant Sudo Privileges to the Git User
1 | chmod 740 /etc/sudoers |
Find the line:
1 | root ALL=(ALL:ALL) ALL |
And add this line below it:
1 | root ALL=(ALL:ALL) ALL |
Save and exit. Then, restore the file permissions:
1 | chmod 440 /etc/sudoers |
- Initialize the Git Repository
Switch to the Git user:
1 | su git # Switch to the Git user |
- Create the Website Directory
1 | cd /var/www/ # Switch to the web server directory |
- Configure SSH
1 | cd /home/git # Go to the Git user's directory |
On your local machine, run:
1 | cat ~/.ssh/id_rsa.pub |
Copy the output and paste it into the authorized_keys file on the server.
- Manage User Groups
Ensure the blog.git, .ssh, and blog directories have the git:git user group permissions:
1 | sudo chown git:git -R /var/www/blog |
Configure Git Hooks
Why set up Git Hooks? The hexo d command only deploys the local public folder to the Git repository. When a new push is received by the Git repository, Git Hooks will copy the contents of the repository to the website directory on the VPS. This process automates transferring the public folder to the VPS’s web root.
- Create the Post-Receive File
Switch to the Git user and go to the hooks directory:
1 | su git # Switch to the Git user |
Copy the following script into the post-receive file:
1 |
|
Save and exit, then give the script executable permissions:
1 | chmod +x post-receive |
Test the Connection
Open a terminal on your local machine and run:
1 | ssh git@vpsip |
If you see “Welcome to…”, the connection was successful.
If the default port is not 22, add the port number:
1 | ssh git@vpsip -p 22 |
Configure Hexo Locally
On your local machine, open the _config.yml file in your blog’s root directory. Find the deploy section and modify it as follows:
1 | deploy: |
Configure Nginx on the Server
Install Nginx
1 | apt-get install nginx |
Configure Nginx
After installation, modify the Nginx server configuration:
1 | cd /etc/nginx/sites-available |
Modify the file as follows:
1 | server { |
Save the changes and start Nginx:
1 | systemctl start nginx # Start Nginx |
At this point, your Hexo website is fully configured and deployed. You can now proceed with regular article publishing.
1 | cd blog |
Other
Cheap VPS Recommendations Page: