使用 Deployer 零停机部署 TYPO3 项目:完整实战指南

发布时间:2026/9/24 0:50:52
使用 Deployer 零停机部署 TYPO3 项目:完整实战指南 DevOpsCI/CDCLI开发工具运维【免费下载链接】deployerThe PHP deployment tool with support for popular frameworks out of the box项目地址https://gitcode.com/gh_mirrors/de/deployer点击查看免费下载TYPO3 是德国企业级 PHP CMS其 Composer 化项目结构public/与var/分离、扩展与语言包管理对部署流水线有特定要求。本文以 Deployer 官方 TYPO3 Reciperecipe/typo3.php为核心系统讲解如何用 Deployer 对 TYPO3 应用实现零停机部署、共享目录、权限修复、扩展安装、缓存刷新与回滚并深入剖析每个配置参数与任务的底层实现确保读者能直接照搬并落地到自己的生产环境。TYPO3 Recipe 是什么TYPO3 Recipe 是 Deployer 为 TYPO3 项目量身定制的部署配方。它建立在 Deployer 通用 Reciperecipe/common.php之上额外预置了 TYPO3 特有的目录约定public/fileadmin、var/log、CLI 命令封装typo3:cache:flush等与 Composer 自动探测逻辑让部署一个 TYPO3 站点从一条条手工 SSH 命令收敛为一条dep deploy命令。在项目deploy.php或 deploy.yaml 等配置文件中引入 Reciperequire recipe/typo3.php;Recipe 内部通过require_once __DIR__ . /common.php和require_once contrib/rsync.php完成依赖加载并调用add(recipes, [typo3])向 Deployer 注册自身见 recipe/typo3.php。引入后你将获得 Deployer 的三大核心能力Provisioning服务器配置通过 provision 系列任务 一键配置服务器环境用户、PHP、Nginx/Caddy 等。零停机部署新版本先发布到独立 release 目录通过原子符号链接切换current部署过程无中断。回滚若新版本出现问题可一键回滚到上一个 release。同时具备易用直观的 DSL 语法、快速并行 SSH 连接、安全全部基于 SSH 执行以及开箱即用地支持主流 PHP 框架等特点。关于 Deployer 的整体入门可阅读 docs/getting-started.md。两种典型用法Git 部署与 rsync 部署TYPO3 Recipe 的注释头部recipe/typo3.php给出了两个最常见的实战场景。场景一生产环境基于 Git 源码部署vendor/bin/dep deploy productionDeployer 会在远端建立 bare 镜像仓库{{deploy_path}}/.dep/repo拉取更新后以git archive方式把目标分支/标签/提交解包到新的 release 目录实现见 recipe/deploy/update_code.php。场景二Staging 环境基于 rsync 部署// 在 deploy.php 或服务器配置中启用 rsync set(use_rsync, true);vendor/bin/dep deploy stagingTYPO3 常用维护命令vendor/bin/dep typo3:cache:flush # 清空所有 TYPO3 缓存 vendor/bin/dep typo3:cache:warmup # 预热系统缓存 vendor/bin/dep typo3:language:update # 更新扩展语言文件 vendor/bin/dep typo3:extension:setup # 安装/设置全部扩展 vendor/bin/dep typo3:install:fixfolderstructure # 自动创建 TYPO3 所需文件与目录配置参数详解TYPO3 Recipe 定义了一组自动化探测的配置项多数具有访问时自动生成Autogenerated的特性——即配置值是闭包在首次读取时才求值。composer_config解析项目根目录composer.json并返回其数组内容用于自动探测 TYPO3 的public_dir与bin_dir等设置。return json_decode(file_get_contents(./composer.json), true, 512, JSON_THROW_ON_ERROR);typo3/public_dirTYPO3 的 publicWeb目录由composer.json自动推导若extra.typo3/cms.web-dir存在则取其值否则默认publicrecipe/typo3.php。set(typo3/public_dir, function () { $composerConfig get(composer_config); if ($composerConfig[extra][typo3/cms][web-dir] ?? false) { return $composerConfig[extra][typo3/cms][web-dir]; } return public; });bin/typo3TYPO3 CLI 二进制路径。优先读取composer.json的config.bin-dir拼成bin-dir/typo3否则默认vendor/bin/typo3recipe/typo3.php。所有 TYPO3 命令都经由{{bin/php}} {{release_path}}/{{bin/typo3}} command执行其中bin/php由 recipe/common.php 定义可用php_version主机属性指定版本否则取which(php)。log_files运行./vendor/bin/dep logs:app时展示的日志文件模式该任务实现见 recipe/common.phpvar/log/typo3_*.logshared_dirs覆盖 recipe/deploy/shared.php 中定义的shared_dirs。这些目录在多个 release 之间持久保留通过shared/目录下的符号链接共享是 TYPO3 上传文件与运行期数据的命脉[ {{typo3/public_dir}}/fileadmin, // 前端上传的文件页面资源、FAL 文件 {{typo3/public_dir}}/typo3temp/assets, // 前端生成资源 var/lock, // 锁文件 var/log, // 日志 var/session, // 会话 var/spool, // 邮件/任务队列 ]注意{{typo3/public_dir}}是可变占位符若你的 composer.json 配置了extra.typo3/cms.web-dir为web这些共享目录会自动解析为web/fileadmin。此外Recipe 还条件性地设置了共享文件recipe/typo3.php——当用户未自定义shared_files时默认共享 TYPO3 的本地配置if (!has(shared_files) || empty(get(shared_files))) { set(shared_files, [ config/system/settings.php, ]); }deploy:shared任务的具体逻辑重复目录校验、从 release 拷贝初始数据到 shared、建立符号链接参见 recipe/deploy/shared.php。writable_dirs覆盖 recipe/deploy/writable.php 中的writable_dirs确保 Web 服务器可写目录[ {{typo3/public_dir}}/fileadmin, {{typo3/public_dir}}/typo3temp/assets, var/cache, var/lock, var/log, ]deploy:writable任务支持chown、chgrp、chmod、acl、sticky、skip六种模式由writable_mode配置默认acl并会自动探测http_user/http_group详细实现见 recipe/deploy/writable.php。若远端未安装 ACL可执行dep run sudo apt-get install acl -- alias安装。composer_options覆盖 recipe/deploy/vendors.php 中的composer_options是生产环境的 Composer 安装参数 --no-dev --verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader即跳过 dev 依赖、优先使用 dist 包、生成优化后的自动加载器。deploy:vendors任务会在release_or_current_path下执行{{bin/composer}} {{composer_action}} {{composer_options}}见 recipe/deploy/vendors.php其中bin/composer支持自动探测或下载 composer.phar。use_rsync 与 update_code_taskuse_rsync默认false使用 Git 仓库若在配置中置为true则切换到 rsync 部署set(use_rsync, false); set(update_code_task, function () { return get(use_rsync) ? rsync : deploy:update_code; });typo3:update_code任务只是简单转发invoke(get(update_code_task))见 recipe/typo3.php这样用户可以在deploy.php中覆写update_code_task指向任意自定义任务。rsyncTYPO3 Recipe 为 rsync 预设了针对性的过滤规则recipe/typo3.php注意这与 Deployer 内置的/src/Utility/Rsync.php不是一回事配置项完全不同contrib/rsync.php 头部有明确警告[ exclude array_merge(get(shared_dirs), get(shared_files), $exclude), exclude-file false, include [vendor], include-file false, filter [dir-merge,-n /.gitignore], filter-file false, filter-perdir false, flags avz, options [delete, keep-dirlinks, links], timeout 600, ]其中$exclude是一份精心挑选的排除清单recipe/typo3.php包括.Build、.git、.ddev、.deployer、node_modules/、var/、/{{typo3/public_dir}}/fileadmin、/{{typo3/public_dir}}/typo3temp等开发与运行期目录——这些内容要么由deploy:shared另行处理要么根本不该上线。同时 rsync 的exclude合并了所有共享目录与共享文件避免重复传输。flags: avz表示归档模式 详细输出 压缩options中的delete删除远端多余文件、keep-dirlinks保留目录链接、links保留符号链接共同保证远端目录与本地严格一致timeout600 秒适合较大代码库。相关参数的行为说明可参考 contrib/rsync.php。TYPO3 专用任务Recipe 定义了一系列 TYPO3 CLI 封装任务全部通过{{bin/php}} {{release_path}}/{{bin/typo3}} command在 release 目录内执行recipe/typo3.php任务说明实际执行的命令typo3:cache:flush清空所有 TYPO3 缓存typo3 cache:flushtypo3:cache:warmup系统缓存预热typo3 cache:warmup --group systemtypo3:language:update更新所有已激活扩展的语言文件typo3 language:updatetypo3:extension:setup安装并配置所有扩展typo3 extension:setuptypo3:install:fixfolderstructure自动创建 TYPO3 所需文件与目录typo3 install:fixfolderstructuretypo3:update_code代码更新Git 或 rsync转发至deploy:update_code或rsync这些任务也可脱离完整部署单独调用例如在开发环境快速刷新缓存vendor/bin/dep typo3:cache:flush vendor/bin/dep typo3:cache:warmup vendor/bin/dep typo3:language:update vendor/bin/dep typo3:extension:setup vendor/bin/dep typo3:install:fixfolderstructuredeploy 主任务完整部署流水线deploy是 TYPO3 Recipe 的主部署任务recipe/typo3.php是一个组合了 14 个子任务的组任务desc(Deploys a TYPO3 project); task(deploy, [ deploy:info, deploy:setup, deploy:lock, deploy:release, typo3:update_code, deploy:shared, deploy:writable, deploy:vendors, typo3:install:fixfolderstructure, typo3:extension:setup, typo3:language:update, typo3:cache:flush, typo3:cache:warmup, deploy:publish, ]);其执行步骤可归纳为 12 个环节锁定部署deploy:lock通过{{deploy_path}}/.dep/deploy.lock文件防止并发部署冲突被锁定时抛出GracefulShutdownException并提示执行deploy:unlock实现见 recipe/deploy/lock.php。创建 release 目录deploy:release清理残留 release 符号链接递增release_name写入.dep/releases_log元信息并建立release软链recipe/deploy/release.php。更新代码typo3:update_code按update_code_task走 Git 或 rsync。共享目录/文件deploy:shared把 fileadmin、var/log 等链接到shared/。修复 TYPO3 目录结构typo3:install:fixfolderstructure。确保可写目录deploy:writable。扩展安装与 Schema 更新typo3:extension:setup。更新语言文件typo3:language:update。安装 Composer 依赖deploy:vendors。刷新缓存typo3:cache:flush。预热缓存typo3:cache:warmup。发布并清理deploy:publish→deploy:symlinkdeploy:unlockdeploy:cleanupdeploy:success见 recipe/common.php。其中第一步deploy:info展示部署信息deploy:setup负责初始化远端目录结构releases/、shared/、.dep/并校验current_path不能是普通目录而应是符号链接recipe/deploy/setup.php。失败兜底Recipe 末尾注册了失败钩子recipe/typo3.phpafter(deploy:failed, deploy:unlock);即一旦部署失败自动解除部署锁避免锁文件残留导致后续部署被卡死。与通用 Recipe 的关系TYPO3 Recipe 基于 recipe/common.php 构建两者配合使用的任务链如下各子任务均可单独调用deploy:info— 展示部署信息docs/recipe/deploy/info.mddeploy:setup— 准备主机环境docs/recipe/deploy/setup.mddeploy:lock / deploy:unlock— 部署锁docs/recipe/deploy/lock.mddeploy:release— 准备 releasedocs/recipe/deploy/release.mddeploy:shared— 共享目录/文件软链docs/recipe/deploy/shared.mddeploy:writable— 可写目录处理docs/recipe/deploy/writable.mddeploy:vendors— Composer 依赖安装docs/recipe/deploy/vendors.mddeploy:symlink / deploy:cleanup / deploy:success— 发布、清理旧版本与成功提示见 docs/recipe/common.md这套分层设计意味着TYPO3 特有的逻辑目录约定、CLI 命令、缓存策略集中在 TYPO3 Recipe 内通用部署机制release 管理、共享目录、锁、回滚则由 common Recipe 统一提供两者职责清晰、可组合可覆写。实战建议首次部署前先在deploy.php中定义好repository、deploy_path与主机列表参考 docs/hosts.md并确认 TYPO3 项目根目录存在composer.json其中extra.typo3/cms.web-dir与config.bin-dir决定 Recipe 的自动探测结果。共享目录别遗漏var/session与var/spool已默认共享若你的扩展在typo3temp或fileadmin之外还有持久化需求记得在deploy.php中追加set(shared_dirs, [...])覆盖默认值。rsync 场景启用use_rsync后建议先查看 contrib/rsync.php 的完整参数说明确认rsync_src/rsync_dest指向正确再执行部署。回滚出现问题时执行vendor/bin/dep rollback实现见 recipe/deploy/rollback.phpDeployer 会重新链接上一个 release配合共享目录实现秒级回滚。缓存预热顺序typo3:extension:setup在typo3:cache:flush之前执行确保扩展安装产生的数据库变更先落库再统一清缓存、最后预热系统缓存避免中间态。至此从配置参数、专用任务到完整部署流水线你已经掌握用 Deployer 生产级部署 TYPO3 的全部要点——剩下的就是在真实服务器上跑通第一次dep deploy production了。赞分享DevOpsCI/CDCLI开发工具运维【免费下载链接】deployerThe PHP deployment tool with support for popular frameworks out of the box项目地址https://gitcode.com/gh_mirrors/de/deployer点击查看免费下载相关推荐使用 Deployer 零停机部署 CodeIgniter 4recipe/codeigniter4 完整实战指南使用 Deployer 零停机部署 CodeIgniter 4recipe/codeigniter4 完整实战指南 本指南讲解如何在 Deployer 中引入DevOpsCI/CDCLI开发工具运维使用 Deployer 零停机部署 Contao 项目完整 Recipe 配置与实战指南使用 Deployer 零停机部署 Contao 项目完整 Recipe 配置与实战指南 导读 本文聚焦于 Deployer 项目中的 Contao 专属部署DevOpsCI/CDCLI开发工具运维使用 Deployer 部署 Magento 项目magento 配方recipe完整解析与零停机发布实战使用 Deployer 部署 Magento 项目magento 配方recipe完整解析与零停机发布实战 导读 本文以 Deployer 开源仓库中的DevOpsCI/CDCLI开发工具运维创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考