在一个 TYPO3 项目中,我正在工作的 Production/Staging(或 Production/Dev,或任何其他)环境受 HTTP BasicAuth(基本访问身份验证)保护。
实例通过typo3/surf部署。
- 在某些时候,typo3/surf 必须创建一个临时 php 文件,该文件可以访问
- 稍后:在切换完成并且可以通过前端访问新部署之后。
如何配置typo3/surf以在BasicAuth 受保护的环境中通过前端访问先前生成的OPcache 清除脚本?
在一个 TYPO3 项目中,我正在工作的 Production/Staging(或 Production/Dev,或任何其他)环境受 HTTP BasicAuth(基本访问身份验证)保护。
实例通过typo3/surf部署。
如何配置typo3/surf以在BasicAuth 受保护的环境中通过前端访问先前生成的OPcache 清除脚本?
\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask
\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask
在早期阶段添加任务(例如package
但绝对在之前transfer
)\TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
\TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
阶段后添加任务switch
由于“尊重 WebDirectory”补丁,脚本的路径不能手动配置,因为它会自动使用正确的 WebDirectory 路径(通过预先选项设置)。
如果您使用的是较旧的typo3/surf 版本,或者您有任何特殊要求,您可以设置选项scriptBasePath
来设置生成文件的绝对路径:
# In this example, I have to set the absolute path for the resulting php file.
# Since the deployment run in GitLab CI I get the path to the root of the project's GIT
# repository via the environment variable `CI_PROJECT_DIR`. Since the path to the webDirectory
# inside the GIT repository is `<GitRepoRootFOlder>/app/web` I add it manually and concatenate
# it as final string for the option `scriptBasePath`:
$workflow->setTaskOptions(\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, [
'scriptBasePath' => \TYPO3\Flow\Utility\Files::concatenatePaths([getenv('CI_PROJECT_DIR'), '/app/web']),
]);
此时,我们提供用户名和密码
$workflow->setTaskOptions('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask', [
'baseUrl' => $application->getOption('baseUrl'),
'stream_context' => [
'http' => [
'header' => 'Authorization: Basic '.base64_encode("username:password"),
],
],
]);
$workflow->beforeStage('transfer', \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, $application)
->afterStage('switch', \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class, $application);
另请查看官方文档中的TYPO3 CMS 部署配置示例。
1 这个答案基于typo3/surf GIT branch dev-master, version 2.x
2放置上述片段的示例:
$deployment->onInitialize(function () use ($deployment, $application) {
/** @var SimpleWorkflow $workflow */
$workflow = $deployment->getWorkflow();
# the mentioned snippets have to be placed next to your existing configuration
});