网站搭建流程记录

网站搭建流程记录

1. 基础设置

1.1 服务器与域名

  • 服务器:购买阿里云轻量服务器。
  • 域名:将域名DNS设置到CloudFlare,并确保完成完整的域名解析。

2. 操作系统初始化

2.1 系统镜像

  • 将VPS初始化为Ubuntu 20.04镜像。

2.2 安装缺失的软件包

  • 更新系统并安装缺失的软件包:
    1
    apt update && apt install zstd

2.3 使用vps2arch脚本

  • 使用肥猫的vps2arch脚本将系统转换为Arch Linux。
  • 重启系统:
    1
    sync ; reboot -f

2.4 配置用户

  • 创建普通用户并加入sudoers组:
    1
    2
    3
    useradd -m -G wheel bla
    passwd bla
    export EDITOR=vim;visudo
    取消注释%wheel ALL=(ALL:ALL) ALL以允许wheel组用户使用sudo。

2.5 禁止root用户SSH登录

  • 修改SSH配置以禁止root用户登录:
    1
    sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config

2.6 提升易用性(可选)

  • 安装常用工具:
    1
    2
    pacman -S wget git stow neofetch lsd htop
    pacman -S zsh oh-my-zsh-git zsh-syntax-highlighting zsh-autosuggestions zsh-history-substring-search
  • 配置zsh:
    1
    2
    3
    cd ~;git clone https://github.com/binbla/dotfiles
    cd ~/dotfiles;stow zsh
    chsh -s /bin/zsh

2.7 配置防火墙

  • 安装并配置UFW防火墙:
    1
    2
    3
    4
    5
    6
    7
    pacman -S ufw
    ufw default deny
    ufw limit ssh
    ufw allow 80
    ufw allow 443
    ufw enable
    systemctl enable ufw

3. 服务器软件安装与配置

3.1 Nginx

  • 安装Nginx:
    1
    2
    3
    pacman -S nginx
    systemctl start nginx
    systemctl enable nginx
  • 使用NginxConfig工具生成配置文件。
  • 配置SSL证书:
    1
    2
    pacman -S certbot certbot-nginx
    certbot --nginx certonly

3.2 MariaDB

  • 安装MariaDB:
    1
    2
    pacman -S mariadb
    mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  • 配置MariaDB:
    1
    2
    3
    sed -i 's/#bind-address=0.0.0.0/bind-address=127.0.0.1/' /etc/my.cnf.d/server.cnf
    systemctl start mariadb
    systemctl enable mariadb
  • 创建数据库和用户:
    1
    2
    3
    4
    5
    6
    7
    mariadb -u root -p
    CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
    CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    GRANT ALL PRIVILEGES ON wordpress_db.* TO 'monty'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    mysql_secure_installation

3.3 PHP

  • 安装PHP和PHP-FPM:
    1
    pacman -S php php-fpm
  • 修改PHP-FPM配置:
    1
    2
    3
    4
    5
    sed -i 's/user = http/user = www/' /etc/php/php-fpm.d/www.conf
    sed -i 's/group = http/group = www/' /etc/php/php-fpm.d/www.conf
    sed -i 's/;extension=mysqli/extension=mysqli/' /etc/php/php.ini
    systemctl start php-fpm
    systemctl enable php-fpm

3.4 Redis

  • 安装Redis及相关PHP扩展:
    1
    pacman -S redis php-redis php-igbinary
  • 启用Redis扩展:
    1
    2
    3
    4
    5
    sed -i 's/;extension=mysqli/extension=mysqli/' /etc/php/php.ini
    sed -i 's/;extension=igbinary.so/extension=igbinary.so/' /etc/php/conf.d/igbinary.ini
    sed -i 's/;extension=redis/extension=redis/' /etc/php/conf.d/redis.ini
    sudo systemctl restart php-fpm
    sudo systemctl restart nginx

4. 总结

通过以上步骤,成功在阿里云服务器上搭建了一个基础的网站环境,包括Nginx、MariaDB、PHP和Redis。