WordPress搭建指南

  1. 更新软件

    sudo apt update
  2. 安装mysql

    1. 安装mysql服务器
      sudo apt install mysql-server
    2. 新建用户
      CREATE USER 'test'@'localhost' IDENTIFIED BY 'password';
      GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;
      CREATE USER 'test'@'%' IDENTIFIED BY 'password';
      GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;
      FLUSH PRIVILEGES;
    3. 修改bind-address

      vim /etc/mysql/mysql.conf.d/mysqld.cnf
      #修改为0.0.0.0
      bind-address = 0.0.0.0
      
      sudo service mysql restart
      sudo ss -tap | grep mysql
    4. 新建数据库
      CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  3. 安装NGINX

    sudo apt install nginx
    

    修改nginx配置文件

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        root /var/www/wordpress;
    
        index index.php index.html index.htm index.nginx-debian.html;
    
        server_name _;
    
        location / {
            try_files $uri $uri/  /index.php =404;
        }
    
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
            include fastcgi_params;
            include snippets/fastcgi-php.conf;
        }
    
        location ~ /\.ht { 
            access_log off; 
            log_not_found off; 
        deny all;
        }
    }
    
    sudo nginx -t
    sudo systemctl reload nginx
  4. 安装PHP

    sudo apt install php php-fpm php-mysql
    sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
  5. 安装WordPress

    wget https://cn.wordpress.org/latest-zh_CN.tar.gz
    
    tar -zxvf latest-zh_CN.tar.gz 
    
    #将解压后的文件夹放入 /var/www/wordpress
    sudo cp wordpress/ /var/www/wordpress
  6. 访问页面http://IP/wp-admin/setup-config.php

    填写数据库连接信息