Error This site can’t be reached

When I open localhost(I set it to php.local ) in browser, I get the following error from browser:

This site can’t be reached

This happens exactly when I use dotenv:

$dotenv = Dotenv\Dotenv::createImmutable(BASEPATH);
$dotenv->load();

This codes Work well with CodeRunner plugin in VSCode.
But it gives an error in the browser unless these lines are commented.

What’s the solution?
The structure and code of my project is as follows.
Structure:

bootstrap
    init.php
vendor
.env
index.php

Pages:

//init.php
<?php
define('BASEPATH', __DIR__ . '/../');

include BASEPATH . '/vendor/autoload.php';

$dotenv = Dotenv\Dotenv::createImmutable(BASEPATH);
$dotenv->load();
//index.php
<?php
include 'bootstrap/init.php';
var_dump($_ENV);

.env:

DB_NAME=mysql
DB_PASS=test

EDIT:
If the .env file is empty, the page will open, but if a value is inserted, it will show this error and the page will not load.

EDIT:
PHP and Apache log errors:

[Wed Jan 19 14:10:03.772224 2022] [php:notice] [pid 14424:tid 1916] [client 127.0.0.1:63640] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
[Wed Jan 19 14:12:39.535296 2022] [mpm_winnt:notice] [pid 13648:tid 676] AH00428: Parent: child process 5308 exited with status 255 -- Restarting.
[Wed Jan 19 14:12:39.668384 2022] [ssl:warn] [pid 13648:tid 676] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Wed Jan 19 14:12:39.691398 2022] [mpm_winnt:notice] [pid 13648:tid 676] AH00455: Apache/2.4.51 (Win64) OpenSSL/1.1.1l PHP/8.1.0 configured -- resuming normal operations
[Wed Jan 19 14:12:39.691398 2022] [mpm_winnt:notice] [pid 13648:tid 676] AH00456: Apache Lounge VS16 Server built: Oct  7 2021 16:27:02
[Wed Jan 19 14:12:39.691398 2022] [core:notice] [pid 13648:tid 676] AH00094: Command line: 'C:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Wed Jan 19 14:12:39.694341 2022] [mpm_winnt:notice] [pid 13648:tid 676] AH00418: Parent: Created child process 17976
[Wed Jan 19 14:12:39.989545 2022] [ssl:warn] [pid 17976:tid 676] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Wed Jan 19 14:12:40.077191 2022] [ssl:warn] [pid 17976:tid 676] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Wed Jan 19 14:12:40.103207 2022] [mpm_winnt:notice] [pid 17976:tid 676] AH00354: Child: Starting 150 worker threads.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.