LinuxCommandLibrary

rails-server

Start the Rails application web server

TLDR

Run the web server

$ rails server
copy

Run the web server on a specified port
$ rails server [[-p|--port]] [port_number]
copy

Run the web server on a specified IP address
$ rails server [[-b|--binding]] [ip_address]
copy

Run the web server on a specified environment
$ rails server [[-e|--environment]] [environment]
copy

Display help
$ rails server [[-h|--help]]
copy

SYNOPSIS

rails server [options]

PARAMETERS

-p, [--port=port]
    Specifies the port to run the server on. Defaults to 3000.

-b, [--binding=host]
    Specifies the IP address to bind to. Defaults to 0.0.0.0, making it accessible from other machines on the network.

-d, [--daemon]
    Runs the server in the background as a daemon.

-e, [--environment=name]
    Specifies the environment to run the server in (development, production, test). Defaults to development.

-P, [--pid=pid]
    Specifies the PID file to use when running as a daemon.

--debugger
    Launches the server with the debugger enabled.

--early-hints
    Enable HTTP/2 early hints.

DESCRIPTION

The `rails server` command starts a local web server for developing and testing Ruby on Rails applications. It simplifies the process of running your Rails application in a development environment, automatically reloading code changes and providing essential tools for debugging and iteration. The command typically boots the Rails environment using the `config/environment.rb` file. By default, it runs on port 3000, but this can be configured. It is essential for local development and testing before deploying to a production environment. It also allows for easy testing of different configurations by passing environment variables (e.g., RAILS_ENV=test) or command-line options. The `rails server` command is a fundamental part of the Rails development workflow.

CAVEATS

Modifying the Rails application's code while the server is running will usually trigger an automatic reload, but this is not always reliable for complex changes or certain configurations. It's generally good practice to restart the server after making significant changes. Ensure that dependencies specified in the Gemfile are installed to avoid runtime errors.

EXAMPLE USAGE

Starting the server on the default port (3000):
rails server

Starting the server on port 4000:
rails server -p 4000

Binding to a specific IP address:
rails server -b 192.168.1.100

Running the server in production environment:
rails server -e production

HISTORY

The `rails server` command evolved along with the Ruby on Rails framework itself. From early versions, it has provided a simple way to run the application for development. Over time, the available options and features have been refined to better support the needs of Rails developers, particularly in managing different environments and debugging.

SEE ALSO

rails console(1), rails db:migrate(1), rails generate(1)

Copied to clipboard