I am new to Rails, so please forgive me if this is obvious.
I am doing a lot of experimenting, creating to applications, testing features, etc. It got my first scaff
In Rails 5 and Puma server, this is the way I could achieve this:
With two terminals, run rails server
in each terminal specifying different Pid files and different ports:
this way, I can simulate two domains for the same app on development
In the current version Rails 5.2.0 and Ruby 2.4.1p111, starting two instances of server for the same app is possible with multiple PIDs.
$ rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Now starting one more server on different port fails with pid issues.
$ rails s -p 3001
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
A server is already running. Check /Users/biju/app1/tmp/pids/server.pid.
Exiting
Below approach of starting server works to use multiple instances of application.
$ rails s -p 3001 -P 321412
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3001
Use Ctrl-C to stop
Thanks for all your help - turns out it was a rather strange occurrence. Somehow, my entire project folder got copied into the Trash. When I started the server, I was starting the server instance in the Trash copy, while the copy I rolled back and edited stay in the same place. Not sure how that happened (perhaps it relates to git, another tool I am just learning). In any case, thanks for all the help, sorry it was something so simple!
You can't really tell the server which application to serve, but you can run a server for each application, and choose which one to load. If you want to run more than one server, you'll have to start them on different ports. The default port is 3000. To start a server on port 3001, run rails s -p 3001
on Rails 3 or script/server -p 3001
on Rails 2.
To start rails server, run the command rails s
or rails server
The following options are valid
-p Port
-b Binding (ip address)
-c Config file (for custom rack configuration)
-d Daemonize server
-u Enable debugger
-e Change the environment (defaults to development)
-P Specify a PID file
So to run an instance to different port in local machine, use the following command
rails s -b 127.0.0.1 -p 8081
Note that you can remove "127.0.0.1" as "localhost" is the default host.
For more information, check this reference http://guides.rubyonrails.org/command_line.html#rails-server
I suspect the old server was still running and the new server failed to start. Try killing it first and then start it your new app.
Alternatively, you could start the new server on a different port by using the -p
switch (e.g. rails server -p 3001
)