How to change Strapi port number 1337 to other number?

Viewed 5711

Recently I tried to use Strapi.

I want run two Strapi apps in single server. So I tried to change default port number - 1337 to other number (For example 1331) In ./config/server.js file.

But when I tried to run Strapi, it failed. In Terminal below is last message, and I can not access admin page - http://localhost:1331/admin

< Opening the admin panel... >

How can I change port number of Strapi?

3 Answers

You can easily change your .env file located in the root project directory adding this line:

PORT=8082

Then save the file, and run this command in order to refresh up all the things:

npm run build

now you can start your server by running:

npm run develop

For Strapi v4, this seem to work, might not be the best way.

config/server.js

module.exports = ({ env }) => ({
  host: env("HOST", "0.0.0.0"),
  port: 1338,
  // port: env.int('PORT', 1337),
  app: {
    keys: env.array("APP_KEYS"),
  },
});
Related