在我正在工作的TYPO3项目中,生产/暂存(或生产/开发或任何其他)环境受HTTP BasicAuth(basic access authentication)保护。
实例get通过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
从“Respect WebDirectory”patch开始,脚本的路径不能手动配置,因为它会自动使用正确的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 deployment configuration example。
1这个答案是基于typo3 / surf GIT branch dev-master,版本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
});