6

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?

Denis Jung
  • 91
  • 1
  • 1
  • 5

4 Answers4

15

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
danduzz
  • 151
  • 1
  • 2
3

You will find option to change the port in config/server.js

Please refer official docs link below fore more information.

https://strapi.io/documentation/v3.x/concepts/configurations.html#server

NS23
  • 684
  • 5
  • 14
  • I tried it already. But it was useless. After change port number in config/server.js file, I run Strapi again. But admin page didn't reply. – Denis Jung Sep 25 '20 at 23:03
  • When I created a Strapi project in my MacBook changing config/server.js was working. But when I created a Strapi project in Cloud server it didn't work. – Denis Jung Sep 30 '20 at 02:57
  • 1
    Cloud server will have its own port..For example In Heroku port is assigned dynamically.. So we have to set Host using env variable. instead of hard coding – NS23 Sep 30 '20 at 07:01
  • In cloud server default setting is working (Not chaning port number in server.js). I have no experience of backend work. I have no idea what I missed. – Denis Jung Oct 01 '20 at 10:52
  • Can you share your default setting ? – NS23 Oct 01 '20 at 13:22
  • I checked cloud platform ACG setting. And I realized I opened TCP port only 1337. After I added another port number, Strapi admin page is working. Thank you. I really appreciate you. Have a great October. – Denis Jung Oct 01 '20 at 14:36
2

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"),
  },
});
atazmin
  • 4,757
  • 1
  • 32
  • 23
0

I had a problem with the port and changed to port: 3000 it worked, but not that much, at least I could show something on the browser, but it wasn't working correctly as it was supposed to work.... then I used: npm run build or yarn build and I have strapi project working well.

Dpv54
  • 1