请注意,本文编写于 358 天前,最后修改于 285 天前,其中某些信息可能已经过时。
容器内手动部署typecho
拉取
ubuntu20.04镜像, 生成并进入容器sudo docker run --name typecho \ --hostname typecho \ -p 20005:8080 -itd \ --restart always \ ubuntu:20.04 sudo docker attach typecho安装必要包
# 更新并安装包 apt install -y vim tmux wget unzip nginx mariadb-server \ php-fpm php-mysql php-gd php-curl php-mbstring php-xml php-zip ## 如果不想在同个容器里集成mysql则无需安装mariadb-server # 启动nginx、mysql和php服务 service nginx start service mysql start service php7.4-fpm start ## php版本可能不一样, 前往/etc/init.d/下查看具体版本
容器环境配置
如果安装了mariadb-server, 则执行以下命令
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
# 登陆进mysql
mysql -u root -p添加数据库、用户及设置密码
CREATE DATABASE typecho;
CREATE USER 'typecho'@'localhost' IDENTIFIED BY '设置一个密码';
GRANT ALL PRIVILEGES ON typecho.* TO 'typecho'@'localhost';
FLUSH PRIVILEGES;
exit;php及nginx配置
# 进入默认路径 cd /var/www/html # 下载官方最新版压缩包 wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip # 在当前目录解压 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 # 设置nginx配置 vim /etc/nginx/sites-available/typechoserver { listen 8080; server_name 127.0.0.1; 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/php7.4-fpm.sock; } location ~ /\.ht { deny all; } }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/php7.4-fpm.sock; } location ~ /\.ht { deny all; } }# 创建软链接, 供nginx调用 ln -sf /etc/nginx/sites-available/typecho /etc/nginx/sites-enabled/ # 删除默认配置 rm /etc/nginx/sites-enabled/default # 测试配置文件是否有错 nginx -t # 重启nginx service nginx restart
文章后续 HTTPS实现
将 Typecho 迁移至 Docker
handsome 主题
假设下载得到的压缩包为
handsome-v9.2.1.zipunzip handsome-v9.2.1.zip sudo docker cp ./主题/handsome typecho:/var/www/html/usr/themes/handsome sudo docker cp ./插件/Handsome typecho:/var/www/html/usr/plugins/Handsome
在docker容器内创建 /var/www/html/usr/music文件夹存放歌曲及歌曲对应图片
然后将mp3文件和图片传到music下
添加歌曲的格式为{"title":"Everything's Alright", "author":"", "url":"http://127.0.0.1:20005/usr/music/1.mp3", "pic":"http://127.0.0.1:20005/usr/music/1.jpeg"}# 修改容器内php设置 vim /etc/php/7.4/fpm/php.inimax_execution_time 3000 max_input_time 600 memory_limit 1280m upload_max_filesize 20G post_max_size 500m max_execution_time 3000# 修改容器内nginx设置 vim /etc/nginx/sites-available/typecho # 在index下加入 client_max_body_size 10g; # 重启php和nginx服务 service php7.4-fpm restart service nginx restart