如何使用typo3 / surf清除BasicAuth受保护环境中的OPcache?

问题描述 投票:0回答:1

在我正在工作的TYPO3项目中,生产/暂存(或生产/开发或任何其他)环境受HTTP BasicAuth(basic access authentication)保护。

实例get通过typo3/surf部署。

  1. 在某些时候,typo3 / surf必须创建一个临时的php文件,可以访问它
  2. 稍后:完成切换后,可以通过前端访问新部署。

如何配置typo3/surf以通过BasicAuth保护环境的前端访问先前生成的OPcache清除脚本?

typo3 basic-authentication typo3-surf
1个回答
0
投票

Configuring typo3/surf to reset the PHP OPcache1

Four steps are basically necessary to configure the OPcache clearing/reset script:

  1. \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask设置任务选项
  2. 在早期阶段添加任务\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask(例如package但绝对在transfer之前)
  3. \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask设置任务选项
  4. 在舞台\TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask之后添加任务switch

以下是部署配置脚本中onInitialize function2的必要代码段:

Set task options for the "Create Script Task":

从“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']),
]);

Set task options for the "Execute Task":

此时,我们提供用户名和密码

$workflow->setTaskOptions('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask', [
    'baseUrl' => $application->getOption('baseUrl'),
    'stream_context' => [
        'http' => [
            'header' => 'Authorization: Basic '.base64_encode("username:password"),
        ],
    ],
]);

Activate both Tasks:

$workflow->beforeStage('transfer', \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, $application)
    ->afterStage('switch', \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class, $application);

这个答案只显示了OPcache重置过程的必要部分!

请查看官方文档中的TYPO3 CMS deployment configuration example


Footnotes

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

});
© www.soinside.com 2019 - 2024. All rights reserved.