Application Ports

Kinsta automatically sets the PORT environment variable. You do not need to define it or hard-code it into the application. Use the PORT environment variable to refer to the port in your application.

If your application’s code specifies or exposes a specific port to listen on, you must use port 8080. When you deploy the application, it will be reachable on the internet on ports 80 and 443, and we will route those ports to the container on port 8080.

Setting a port other than 8080 for the application inside the container is not currently possible. If your application tries to set the port to anything other than 8080, you won’t be able to access the application.

PORT Environment Variable Language Examples

How you use an environment variable is up to your application. The following table shows how to call the PORT environment variable in various languages:

Language Code
Ruby ENV["PORT"]
Node.js process.env.PORT;
Python os.environ.get('PORT')
Java System.getenv("PORT");
Scala System.getenv("PORT");
PHP getenv('PORT');
Go os.Getenv("PORT")

Database Ports

Only the port shown in Info > External connections is open for Database Hosting. To connect the database to an external application, use the port and other external connection details shown there.

If you are connecting an application and database that are both hosted on Kinsta, make sure they use the same data center location and are connected by an internal connection.

Related Documentation