Generally on starting the server, it takes port 3000. If you want to change port then we can specify port number manually by appending our rails s with -p port_no. But we can change our default port no by adding few lines of codes.
With Following Command our Rails Server starts at Default port 3000 :
$ rails s
If we wish to start it at different port,we manually enter Following command : (for Starting it at port 3010)
$ rails s -p 3010
Let’s make this 3010 port our default port, i.e. when ever we start server by “rails s”, BY DEFAULT our application should run on port 3010.
Open your boot.rb file located at : Project Name / config / boot.rb :
Add Following lines of code in the file : (Simply append don’t replace existing Codes)
require 'rails/commands/server' module Rails class Server alias :default_options_alias :default_options def default_options default_options_alias.merge!(:Port => 3010) end end end
Now let’s run our command to start our Server and look at the log.
$ rails s => Booting WEBrick => Rails 3.2.13 application starting in development on http://0.0.0.0:3010 => Call with -d to detach => Ctrl-C to shutdown server [2013-09-21 12:59:27] INFO WEBrick 1.3.1 [2013-09-21 12:59:53] INFO ruby 1.9.3 (2013-02-22) [i386-mingw32] [2013-09-21 12:59:53] INFO WEBrick::HTTPServer#start: pid=5340 port=3010
Our webrick started on port 3010.