使用的是Debian 11系统

  1. 更新系统
apt update
apt upgrade -y
  1. 安装 Nginx
apt install nginx -y
systemctl start nginx
systemctl enable nginx
  1. 安装 MySQL(MariaDB)
apt install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb

如有指定需求可指定版本
配置 MySQL 安全性

mysql_secure_installation

在执行 mysql_secure_installation 时,会问你几个问题:

Enter current password for root: 直接按回车
Set root password? [Y/n]:输入 Y,然后设置 root 密码
Remove anonymous users? [Y/n]:输入 Y
Disallow root login remotely? [Y/n]:输入 Y
Remove test database? [Y/n]:输入 Y
Reload privilege tables now? [Y/n]:输入 Y
  1. 为 Typecho 创建数据库和用户
mysql -u root -p

使用root身份连接mysql -u表示指定用户名 -p表示需要输入密码
在 MySQL 命令行中执行:

CREATE DATABASE typecho;
CREATE USER 'typecho'@'localhost' IDENTIFIED BY '设置一个密码';
GRANT ALL PRIVILEGES ON typecho.* TO 'typecho'@'localhost';
FLUSH PRIVILEGES;
exit;

创建名为typecho的数据库,并创建一个typecho用户,指定其此用户仅允许本地访问,且设置一个密码,然后并授予该用户对 typecho 数据库的所有权限。最后刷新一下。

  1. 安装 PHP 及必要扩展
apt install php-fpm php-mysql php-gd php-curl php-mbstring php-xml php-zip -y
systemctl start php7.4-fpm
systemctl enable php7.4-fpm

在 Debian 11 中:PHP 默认是 7.4,如有指定需求可指定版本,指定版本后,记得修改nginx配置文件中对应的部分。例如指定为8.0,那么php7.4-fpm.sock应该为php8.0-fpm.sock。

  1. 下载和配置 Typecho
cd /var/www/html
wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip
apt install unzip -y
unzip typecho.zip
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
chmod -R 777 /var/www/html/usr/uploads

远程下载typecho源文件并解压
将 /var/www/html 及其所有文件和子目录的所有者和所属组设置为 www-data,www-data 是 Apache 或 Nginx Web 服务器通常使用的用户和组。

  1. 配置 Nginx
nano /etc/nginx/sites-available/typecho

方式一:通过域名访问的配置

server {
    listen 80;
    server_name examle.com;  # 替换为你的域名或服务器IP
    root /var/www/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

方式二:通过ip+端口访问的配置

server {
    listen 8080;  # 改为你想要的端口号
    server_name 你的服务器IP;  # 直接填写服务器IP
    root /var/www/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}
  1. 启用站点配置
ln -sf /etc/nginx/sites-available/typecho /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
nginx -t
systemctl restart nginx
  1. 访问网站完成安装

现在可以通过浏览器访问你的域名或服务器IP,会看到 Typecho 的安装界面。按照以下步骤完成安装:

选择"开始安装"
数据库适配器选择 "MySQL"
数据库地址填写 "localhost"
数据库端口保持默认 "3306"
数据库用户名填写 "typecho"
数据库密码填写你之前设置的密码
数据库名填写 "typecho"
创建管理员账号和密码

注意事项:
如果没有安装防火墙,可跳过。
如果安装了防火墙,请确保防火墙允许 80 端口访问:

apt install ufw
ufw allow 80/tcp
ufw enable

如果遇到权限问题,可以检查:

chmod -R 755 /var/www/html
chown -R www-data:www-data /var/www/html

如果网站打不开,可以查看日志:

tail -f /var/log/nginx/error.log

定期备份数据:

mysqldump -u root -p typecho > typecho_backup.sql

最后修改:2024 年 12 月 17 日
如果觉得我的文章对你有用,请随意赞赏