localhost:4000: Jekyll, Phoenix and Apollo

Three popular tools serve on localhost:4000 by default: Jekyll's bundle exec jekyll serve, Elixir's Phoenix framework, and the standalone Apollo GraphQL server. If the page refuses to connect, the build likely failed before the server started. With Jekyll, a baseurl setting can also move the site to a subpath.

Defaults on port 4000
ToolStart commandOther port
Jekyllbundle exec jekyll serve--port 4001
Phoenixmix phx.serverPORT=4001 mix phx.server (if config reads PORT)
Apollo Server (standalone)node index.jslisten: { port: 4001 }

Updated

Port 4000 is popular because it is easy to remember and rarely used by operating systems. That also means conflicts here are almost always two of your own projects running at once.

Serve Jekyll reliably

Install, add webrick, serve

--livereload refreshes the browser when files change.

bundle add webrick
bundle exec jekyll serve --port 4000 --livereload
# from another device on the network
bundle exec jekyll serve --host 0.0.0.0

Static site preview versus a live site

Jekyll's server only previews the generated _site folder; it is not meant to host the site publicly. Deploy the built files to a static host when you are ready.

If writing Markdown and running Ruby is more than you want for a blog, We.Inc can produce a hosted site with a blog from a short description.

How it works

  1. Run the tool and read the address it prints, such as 'Server address: http://127.0.0.1:4000/'.
  2. If there is no address, fix the first error above it.
  3. Free the port if another project holds it.
  4. Open the exact URL, including any baseurl path.

Tips

  • Jekyll with baseurl: /blog in _config.yml serves at localhost:4000/blog/, so the root URL shows a 404.
  • Jekyll on Ruby 3 needs gem webrick added to the Gemfile, or serve exits with a load error.
  • Phoenix reads the port from config/dev.exs, so changing it there is permanent for the project.
  • Apollo Server 4 prints 'Server ready at http://localhost:4000/' only after the schema loads without errors.

Frequently asked questions

What runs on localhost:4000?

Most often Jekyll, Phoenix or Apollo Server, which all choose 4000 by default. Whichever you started last is the one answering.

Why does jekyll serve fail with 'Address already in use'?

Another Jekyll or program holds 4000. Stop it with lsof -i :4000 and kill, or run bundle exec jekyll serve --port 4001.

Why does Jekyll show a 404 at localhost:4000?

Your _config.yml probably sets a baseurl. Open localhost:4000 followed by that path, or leave baseurl empty for local work.

How do I open localhost:4000 from my phone?

Bind to all addresses, for example jekyll serve --host 0.0.0.0, then use your computer's local IP and port 4000 from the phone on the same Wi-Fi.

Related: Static site generators, localhost:3001, GraphQL vs REST, localhost refused to connect.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

Product

Who It's For

Features

Resources

Company

View Sitemap