阿里云服务器Ubuntu-22.04安装typecho搭建个人博客

1. 更新系统并安装必要组件

sudo apt update
sudo apt upgrade -y

# 安装 Nginx、MySQL、PHP 及扩展
sudo apt install nginx mysql-server php-fpm php-mysql php-curl php-mbstring php-xml php-gd php-zip unzip wget -y

2. 启动并设置服务开机自启

sudo systemctl enable nginx
sudo systemctl start nginx

sudo systemctl enable mysql
sudo systemctl start mysql

sudo systemctl enable php8.1-fpm
sudo systemctl start  php8.1-fpm

3. 配置 MySQL 数据库

登录 MySQL:

sudo mysql -u root

创建数据库和用户(密码请替换为强密码):

CREATE DATABASE typecho_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'typecho_user'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT ALL PRIVILEGES ON typecho_db.* TO 'typecho_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

4. 下载并部署 Typecho

切换到网站根目录:

mkdir /var/www/typecho
cd /var/www/typecho

下载最新 Typecho:

使用XFTP传入文件到/var/www/typecho

解压文件

unzip typecho.zip

设置权限

sudo chown -R www-data:www-data /var/www/typecho
sudo chmod -R 755 /var/www/typecho

5. 配置 Nginx

1. 编辑站点配置

sudo vim /etc/nginx/sites-available/typecho

根据自己实际情况配置

server {
    listen 80;
    server_name your_server_ip_or_domain # 替换为你的服务器IP或域名;

    root /var/www/typecho;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;  # 确认自己的php-fpm版本
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }
}

软链接到/etc/nginx/sites-enabled

sudo ln -s /etc/nginx/sites-available/typecho /etc/nginx/sites-enabled/typecho

2. 测试配置

sudo nginx -t

确保没错误。

3. 重载 Nginx

sudo systemctl reload nginx

6. 访问安装页面

在浏览器访问:

http://你的服务器IP/

点击下一步

查询自己的数据库用户

填写相应信息即可

7.设置butterfly主题

搜索butterfly,点击Release进行下载

上传到themes文件夹内

sudo unzip butterfly_Release1.8.1.zip
sudo chown -R www-data:www-data butterfly
sudo chmod -R 755 butterfly

进入后台界面,启用该主题