I set the port as 3000 in my application.yml (figaro managing env variables)
rails s
uses port 3000
but when I run foreman start
(as recommended by Her
Use a .foreman file with:
port: 3000
or a .env file with:
PORT=3000
Either one should work, then you can just use foreman start
port ENV['PORT'] || 3000
This line says that you will attempt to use ENV['PORT']
first and if that doesn't exist, you will fall back to using 3000
as the port number. So are you defining PORT
environment variable anywhere prior to foreman
starting? config/application.yml
environment variables only will be loaded after the rails server starts, so it's no use defining port number here.
You can try adding
PORT=3000
in .env
file in the root of the project directory.
Source: https://devcenter.heroku.com/articles/getting-started-with-rails5#procfile
Mystery on the puma port solved.
Put this print in your config/puma.rb
Then you'll see that somehow the port is mysteriously set to 5000 even though it is not in your ENV.
Fix at bottom.
puma_port = ENV['PORT'] || 3000
puts "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
puts "puma_port is #{puma_port}"
puts "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ”
That prints out
16:49:28 web.1 | ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
16:49:28 web.1 | puma_port is 5000
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
Then place this line in your Procfile (not the one you use for Heroku). I've got one called Procfile.dev
web: PORT=3000 bundle exec puma -C config/puma.rb
And I run it with this command:
foreman start -f Procfile.dev