{"record":{"id":"221493aa086a3751","repo":"flarum/framework","slug":"please-provide-a-valid-port-number-between-1-and-65535","errorCode":null,"errorMessage":"Please provide a valid port number between 1 and 65535.","messagePattern":"Please provide a valid port number between 1 and 65535\\.","errorType":"validation","errorClass":"ValidationFailed","httpStatus":null,"severity":"error","filePath":"framework/core/src/Install/DatabaseConfig.php","lineNumber":56,"sourceCode":"        ], $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\n        if (! empty($this->prefix)) {\n            if (! preg_match('/^[\\pL\\pM\\pN_]+$/u', $this->prefix)) {\n                throw new ValidationFailed('The prefix may only contain characters and underscores.');\n            }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Install/DatabaseConfig.php#L38-L74","documentation":"ValidationFailed thrown by DatabaseConfig::validate when the port is outside 1-65535 for mysql, mariadb or pgsql drivers. It ensures the port is a usable TCP port number before the installer attempts a connection. SQLite again is exempt since it does not connect over TCP.","triggerScenarios":"Constructing DatabaseConfig with a port of 0, negative, >65535, or an unset/null port for a TCP-based driver.","commonSituations":"DB_PORT env var left empty or set to a non-numeric placeholder; typo like 3306033; copying a redis (6379) or http (80) port into the DB config; missing default when the form field is blank.","solutions":["Set the port to the correct server port: 3306 for MySQL/MariaDB, 5432 for PostgreSQL.","If the env value may be blank, apply the driver default before constructing DatabaseConfig.","Cast/validate the value as an integer in (1..65535) before passing it in.","Switch to sqlite driver if no TCP database is intended."],"exampleFix":"// before\nnew DatabaseConfig(driver: 'mysql', host: 'db', port: 0, database: 'app');\n// after\nnew DatabaseConfig(driver: 'mysql', host: 'db', port: 3306, database: 'app');","handlingStrategy":"validation","validationCode":"$port = (int) ($env['DB_PORT'] ?: match($driver) { 'pgsql' => 5432, default => 3306 });\nif ($port < 1 || $port > 65535) {\n    throw new InvalidArgumentException('DB_PORT must be between 1 and 65535');\n}\n$config = new DatabaseConfig(driver: $driver, host: $host, port: $port, database: $database);","typeGuard":"function isValidPort(mixed $port): bool {\n    return is_int($port) && $port >= 1 && $port <= 65535;\n}","tryCatchPattern":"try {\n    $config = new DatabaseConfig(...$input);\n} catch (ValidationFailed $e) {\n    if (str_contains($e->getMessage(), 'port')) {\n        $errors['port'] = 'Use 3306 (MySQL/MariaDB) or 5432 (PostgreSQL).';\n    }\n}","preventionTips":["Default the port per driver instead of leaving it blank.","Validate DB_PORT is numeric and in range when parsing .env.","Do not reuse ports from other services in DB config."],"tags":["database","config","port","validation"],"backgroundTag":"value-out-of-range","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"}