public function setup(ServerRequestInterface $request): ResponseInterface
    {
        // Mini "bootstrap"
        define('WT_DATA_DIR', 'data/');
        app()->instance(ServerRequestInterface::class, $request);
        app()->instance('cache.array', new Repository(new ArrayStore()));

        $data = $this->userData($request);

        $step = (int) ($request->getParsedBody()['step'] ?? '1');
        $lang = $request->getParsedBody()['lang'] ?? $data['lang'];

        $data['lang']         = I18N::init($lang, null, true);
        $data['cpu_limit']    = $this->maxExecutionTime();
        $data['locales']      = $this->setupLocales();
        $data['memory_limit'] = $this->memoryLimit();

        // Only show database errors after the user has chosen a driver.
        if ($step >= 4) {
            $data['errors']   = $this->server_check_service->serverErrors($data['dbtype']);
            $data['warnings'] = $this->server_check_service->serverWarnings($data['dbtype']);
        } else {
            $data['errors']   = $this->server_check_service->serverErrors();
            $data['warnings'] = $this->server_check_service->serverWarnings();
        }

        if (!$this->checkFolderIsWritable(WT_DATA_DIR)) {
            $data['errors']->push(
                '<code>' . e(realpath(WT_DATA_DIR)) . '</code><br>' .
                I18N::translate('Oops! webtrees was unable to create files in this folder.') . ' ' .
                I18N::translate('This usually means that you need to change the folder permissions to 777.')
            );
        }

        define('WT_LOCALE', $data['lang']);

        switch ($step) {
            default:
            case 1:
                return $this->step1Language($data);
            case 2:
                return $this->step2CheckServer($data);
            case 3:
                return $this->step3DatabaseType($data);
            case 4:
                return $this->step4DatabaseConnection($data);
            case 5:
                return $this->step5Administrator($data);
            case 6:
                return $this->step6Install($data);
        }
    }