在Ubuntu子系统中基于Nginx部署Typecho

发布于:2025-02-10 ⋅ 阅读:(44) ⋅ 点赞:(0)
  1. 下载部署程序
    typecho
  2. 上传文件到子系统
  • 创建文件夹typecho
    在目录/var/www/html中创建一个目录typecho
cd /var/www/html
mkdir typecho
  • 将文件typecho.zip上传至新建的目录下,并解压文件
unzip typecho.zip
  • 授权文件夹
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
  1. 使用apt安装php以及nginx
apt install nginx
sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-xmlrpc php-zip
  1. 启动php8.1-fpm
sudo service php8.1-fpm start
sudo service php8.1-fpm status
  1. 添加nginx配置文件
    /etc/nginx/sites-available目录中创建一个typecho.conf的配置文件
    命令如下
    vim /etc/nginx/sites-available/typecho.conf
    在文件中输入以下内容
server {
    listen       80;
    server_name  127.0.0.1;  # 将这里替换为你的域名或服务器IP

    root /var/www/html/typecho;  # Typecho安装目录

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;  # 根据你的PHP版本修改
    }

    location ~ /\.ht {
        deny all;
    }
}
  1. 将配置文件链接到/etc/nginx/sites-enabled/目录
    命令如下:
    sudo ln -s /etc/nginx/sites-available/typecho.conf /etc/nginx/sites-enabled/
  2. 检查Nginx并重启
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo service nginx restart
  1. 在浏览器中访问你的服务器IP
    http://127.0.0.1/install.php
    开始 Typecho 的安装向导,按照提示填写数据库信息等,完成 Typecho 的安装