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:
- You run
php bin/grav serverand it starts without any errors. - The terminal shows
[OK] Built-in PHP web server listening on http://127.0.0.1:8000. - When you try to open
http://127.0.0.1:8000in your browser, you get a “Connection Failed” or “Unable to Connect” error. - Meanwhile, the terminal log shows successful
[200] OKresponses for your requests. - Clearing the browser cache, using incognito mode, or trying a different browser does not help.
- 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:
- Your browser requests
http://127.0.0.1:8000. - Grav processes the request, sees
force_ssl: true, and sends back a redirect tohttps://127.0.0.1:8000. This is the successful[200] OKresponse you see in the log. - Your browser follows the redirect and tries to connect to the
https://address. - 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):
- Open your
user/config/system.yamlfile. - Find the line
force_ssl: true. - Change it to
force_ssl: false. - 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!