[SOLVED] Local server starts (200 OK) but browser can't connect - A tip for beginners

Hello, Grav community!

I want to share a solution to a problem that was very tricky to debug. I’m posting this because I think it could be a common pitfall for developers who are new to Grav or setting up a local environment from a live project.

The Symptoms:

  1. You run php bin/grav server and it starts without any errors.
  2. The terminal shows [OK] Built-in PHP web server listening on http://127.0.0.1:8000.
  3. When you try to open http://127.0.0.1:8000 in your browser, you get a “Connection Failed” or “Unable to Connect” error.
  4. Meanwhile, the terminal log shows successful [200] OK responses for your requests.
  5. Clearing the browser cache, using incognito mode, or trying a different browser does not help.
  6. You’ve confirmed all required PHP extensions (intl, yaml, etc.) are installed and working correctly via php -m.

The Real Cause & Solution:

You are correct that Grav’s default setting is not the issue. The problem happens when a site is moved from a live production server to a local machine for development.

On a live server, it’s common (and recommended) to enforce SSL. This is done in user/config/system.yaml by setting:

force_ssl: true

The issue is that the simple built-in PHP server, which we use for local development, does not support HTTPS.

So, this is the sequence of events that causes the failure:

  1. Your browser requests http://127.0.0.1:8000.
  2. Grav processes the request, sees force_ssl: true, and sends back a redirect to https://127.0.0.1:8000. This is the successful [200] OK response you see in the log.
  3. Your browser follows the redirect and tries to connect to the https:// address.
  4. The local PHP server cannot handle the https:// request and drops the connection, resulting in the error in your browser.

THE SOLUTION (for your local environment):

  1. Open your user/config/system.yaml file.
  2. Find the line force_ssl: true.
  3. Change it to force_ssl: false.
  4. Save the file and restart your local server (php bin/grav server).

After this change, your local site should load perfectly. Just remember to set it back to true if you are deploying your changes to a live production server that uses SSL.

Hope this helps someone else!

Much better to post a solution as a separate post and mark it as such