{"record":{"id":"f39935f8239be552","repo":"flarum/framework","slug":"please-specify-the-hostname-of-your-database-server","errorCode":null,"errorMessage":"Please specify the hostname of your database server.","messagePattern":"Please specify the hostname of your database server\\.","errorType":"validation","errorClass":"ValidationFailed","httpStatus":null,"severity":"error","filePath":"framework/core/src/Install/DatabaseConfig.php","lineNumber":52,"sourceCode":"            'driver' => $this->driver,\n            'database' => $this->database,\n            'prefix' => $this->prefix,\n            'prefix_indexes' => true\n        ], $this->driverOptions());\n    }\n\n    private function validate(): void\n    {\n        if (empty($this->driver)) {\n            throw new ValidationFailed('Please specify a database driver.');\n        }\n\n        if (! in_array($this->driver, ['mysql', 'mariadb', 'sqlite', 'pgsql'])) {\n            throw new ValidationFailed('Currently, only MySQL, MariaDB, SQLite and PostgreSQL are supported.');\n        }\n\n        if (empty($this->host) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {\n            throw new ValidationFailed('Please specify the hostname of your database server.');\n        }\n\n        if (($this->port < 1 || $this->port > 65535) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {\n            throw new ValidationFailed('Please provide a valid port number between 1 and 65535.');\n        }\n\n        if (empty($this->database)) {\n            throw new ValidationFailed('Please specify the database name.');\n        }\n\n        if (empty($this->schema) && $this->driver == 'pgsql') {\n            throw new ValidationFailed('Please specify the schema name.');\n        }\n\n        if (empty($this->username) && in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {\n            throw new ValidationFailed('Please specify the username for accessing the database.');\n        }\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Install/DatabaseConfig.php#L34-L70","documentation":"ValidationFailed thrown by DatabaseConfig::validate during installation when the database host is empty for a network-based driver. SQLite is file-based and needs no host, but MySQL, MariaDB and PostgreSQL require a server hostname. The check runs in the constructor, so invalid config fails fast before any connection is attempted.","triggerScenarios":"Constructing DatabaseConfig with driver mysql/mariadb/pgsql and an empty or unset host property (e.g. missing DB_HOST in the installer form or config).","commonSituations":"Install wizard where the hostname field was left blank; .env with DB_HOST missing; copying a sqlite-oriented config to a MySQL install; localhost configured only for the sqlite driver.","solutions":["Set the host property (or DB_HOST env) to your database server hostname or IP before constructing DatabaseConfig.","Use 'localhost' or '127.0.0.1' if the database runs on the same machine.","If you intend to use SQLite, switch the driver to 'sqlite' so the host check is skipped."],"exampleFix":"// before\nnew DatabaseConfig(driver: 'mysql', host: '', database: 'flarum');\n// after\nnew DatabaseConfig(driver: 'mysql', host: '127.0.0.1', database: 'flarum');","handlingStrategy":"validation","validationCode":"if (in_array($driver, ['mysql','mariadb','pgsql'], true) && trim((string) $host) === '') {\n    throw new InvalidArgumentException('DB host is required for '.$driver);\n}\n$config = new DatabaseConfig(driver: $driver, host: $host, database: $database);","typeGuard":"function hasHost(array $cfg): bool {\n    return isset($cfg['host']) && is_string($cfg['host']) && trim($cfg['host']) !== '';\n}","tryCatchPattern":"try {\n    $config = new DatabaseConfig(...$input);\n} catch (ValidationFailed $e) {\n    if (str_contains($e->getMessage(), 'hostname')) {\n        $errors['host'] = 'Hostname is required for this driver.';\n    }\n}","preventionTips":["Validate DB_HOST is non-empty in installer forms before submitting.","Give drivers that need a host a required marker in the UI.","Default host to 127.0.0.1 for local installs."],"tags":["database","config","validation","install"],"backgroundTag":"missing-required-config-field","analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}