In the wave of digitalization, an efficient and stable content management system (CMS) is an indispensable foundation for both enterprises and individuals to operate websites.AnQiCMS (AnQiCMS) is an enterprise-level CMS developed based on the Go language, with excellent performance, security, and flexible scalability, winning a good reputation in the industry.It is particularly suitable for users who pursue lightweight, efficient, and customizable solutions, whether they are small and medium-sized enterprises, self-media, or multi-site administrators.

Many senior system administrators and developers tend to deploy applications on Linux servers without a graphical interface, which not only maximizes the use of server resources but also provides higher security and more flexible control.This article will focus on this requirement, elaborating on how to efficiently and stably deploy AnQiCMS in a command-line environment, so that your website runs smoothly on the solid foundation of Linux.


Deploy AnQiCMS efficiently in a pure command-line environment

Deploying AnQiCMS on a Linux server without a visual panel means that you will connect to the server via SSH and operate throughout using the command line.This approach may seem daunting at first glance, but once mastered, you will have a deeper understanding and control over servers and applications, which is the essence of efficient operation and maintenance.

Before starting the deployment of AnQiCMS, you need to ensure that the server environment is ready.This usually includes a server running a Linux distribution (such as Ubuntu, CentOS, etc.), which is already configured with a web server (Nginx or Apache) for reverse proxy, as well as a database service (MySQL is recommended), all of which are the foundation for backend application operation and data storage.Assume you already have these basic environments.

First step: Download and unzip the AnQiCMS installation package

The first step in deploying AnQiCMS is to download the installation package to your Linux server.You can download the latest Linux version installation package from the AnQiCMS official website.This is usually a compressed file, such asanqicms-linux-v3.x.x.zip.

BywgetorcurlThe command can directly download the package to the server:

wget https://en.anqicms.com/download/anqicms-linux-v3.x.x.zip

After the download is complete, we need to create a dedicated directory to store the AnQiCMS program. For example, we choose to place it in/www/wwwroot/Create a directory named after your domain, which helps in multi-site management and permission isolation:

mkdir -p /www/wwwroot/yourdomain.com
cd /www/wwwroot/yourdomain.com

Next, move the downloaded installation package to this newly created directory and extract it. If the command is not available on the serverunzipyou may need to install it first (such assudo apt install unziporsudo yum install unzip)

mv /path/to/anqicms-linux-v3.x.x.zip .
unzip anqicms-linux-v3.x.x.zip

After unzipping, you will see a file namedanqicmsan executable file and other necessary files and directories such aspublic(static resources),template(template files) and so on.

Step 2: Configure the automatic startup and monitoring of AnQiCMS service

AnQiCMS is a Go language application, compiled into a standalone binary file. To ensure that the service can run continuously, even if the server restarts, and can automatically start and recover if the program stops unexpectedly, we need to usecrontabSet a guardian task.

First, edit the crontab configuration:

crontab -e

This will open a text editor where you can add scheduled tasks. Add the following two lines at the end of the file:

*/1 * * * * /www/wwwroot/yourdomain.com/start.sh
@reboot /www/wwwroot/yourdomain.com/start.sh

The first line indicates that the AnQiCMS running status is checked every minute. If it is not running, it will start it, serving as a guardian process.The second line ensures that AnQiCMS can start immediately after the server restart.

Herestart.shIs the startup script bundled with the AnQiCMS installation package, it will checkanqicmsWhether the process exists, if it does not exist, it will be started in the background (nohup). Please make sure to confirm.start.shin the scriptBINPATHandBINNAMEThe variable points to the correct path and executable file name. If your AnQiCMS executable file is notanqicms, please editstart.shto make the modification.

After addingcrontabAfter the task, you need to manually execute oncestart.shScript to immediately start the AnQiCMS service:

cd /www/wwwroot/yourdomain.com
./start.sh

At this time, the AnQiCMS service is already running in the background, defaulting to listen on8001on the port.

Step 3: Configure the reverse proxy of the web server

Due to AnQiCMS defaulting to listen on a non-standard port (8001), we need a web server (Nginx or Apache) as a frontend to receive users' HTTP/HTTPS requests and then forward them to the AnQiCMS service.This is called reverse proxy, it not only allows websites to access through standard ports (80 or 443), but also provides advanced features such as SSL certificates, load balancing, caching, etc.

For example, using Nginx, you need to edit or create a configuration file for the Nginx site. This file is usually located/etc/nginx/conf.d/or/etc/nginx/sites-available/In the directory. For example, create a file namedyourdomain.com.conffile:

sudo vim /etc/nginx/conf.d/yourdomain.com.conf

Add the following Nginx configuration in the file:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com; # 替换为您的实际域名

    # 网站根目录指向AnQiCMS的public目录
    root /www/wwwroot/yourdomain.com/public;

    # AnQiCMS的反向代理配置
    location @AnqiCMS {
        proxy_pass http://127.0.0.1:8001; # AnQiCMS监听的端口
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # 优先尝试匹配文件,如果找不到,则交由AnqiCMS处理
    location / {
       try_files $uri $uri/index.html @AnqiCMS;
    }

    # 可选:配置SSL证书
    # listen 443 ssl;
    # ssl_certificate /etc/nginx/ssl/yourdomain.com.pem;
    # ssl_certificate_key /etc/nginx/ssl/yourdomain.com.key;

    access_log /var/log/nginx/yourdomain.com_access.log;
    error_log /var/log/nginx/yourdomain.com_error.log;
}

Configuration points to note:

  • listen 80;andserver_name yourdomain.com www.yourdomain.com;: Defines the listening port and your website domain.
  • root /www/wwwroot/yourdomain.com/public;:Very importantSet Nginx's document root directory to the AnQiCMS program directory underpublicfolder, which is the place to store static resources.
  • location @AnqiCMS { ... }: Defined an internal forwarding rule to proxy requests locally8001Port running AnQiCMS service.
  • try_files $uri $uri/index.html @AnqiCMS;: This is the core pseudo-static rule. It first tries to find inpublicLook for the requested URI (such as static files) in the directory, if not found, try to look for itindex.htmlIf it is still not found, then forward the request to@AnqiCMSHandle. This can make use of Nginx to efficiently process static files and hand over dynamic requests to AnQiCMS.
  • error_page 404 =200 @AnqiCMS;Ensure that 404 errors can also be handled by AnQiCMS while maintaining URL consistency.

Save and close the configuration file after, you need to check the syntax of the Nginx configuration file and reload the Nginx service to make the configuration take effect: “`bash