Changing hostname and port with Vapor 3

Be sure you are using the Vapor 3 version then use this:

vapor run --hostname=0.0.0.0 --port=8080

If you don't add = after the parameter, you are going to receive the follow complaint:

CommandError: Unknown command 8080

If you do as I recommended above, you are going to receive:

[Deprecated] --option=value syntax is deprecated.

Please use --option value (with no =) instead but the command will run and works fine.

I was unable to find a way to run this command without = after the parameter.


Currently, you can set the port and hostname when running your server:

swift run Run --hostname 0.0.0.0 --port 9000

There appears to be struct-based configuration for EngineServer but I don’t think it is configurable at run time just yet. The last time the Vapor developer answered this question (on their Slack) the command-line argument method was the suggested one.


in Vapor 4

app.http.server.configuration.hostname = "127.0.0.1"
app.http.server.configuration.port = 8000

in Vapor 3

services.register(NIOServerConfig.default(hostname: "127.0.0.1", port: 8000))

Official Solution (as sanctioned by the maintainers)

You can use NIOServerConfig.

let serverConfiure = NIOServerConfig.default(hostname: "0.0.0.0", port: 9090)
services.register(serverConfiure)

Vapor version is 3.0.3