How to run the Built-in PHP HTTP server?
I'm trying to run php-solid-server without the Docker image by running:
$ HOST=127.0.0.1 composer serve-dev
Browsing to http://127.0.0.1:8080 I get this error below. Any hints what I should do?
Static route "/" is shadowed by previously defined variable route "/((?:.|/)*)" for method "GET" (FastRoute\BadRouteException)
/Users/patrickhochstenbach/Dev/php-solid-server-0.6.2/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php:95
#0 /Users/patrickhochstenbach/Dev/php-solid-server-0.6.2/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php(30): FastRoute\DataGenerator\RegexBasedAbstract->addStaticRoute('GET', Array, Object(League\Route\Route))
#1 /Users/patrickhochstenbach/Dev/php-solid-server-0.6.2/vendor/nikic/fast-route/src/RouteCollector.php(44): FastRoute\DataGenerator\RegexBasedAbstract->addRoute('GET', Array, Object(League\Route\Route))
#2 /Users/patrickhochstenbach/Dev/php-solid-server-0.6.2/vendor/league/route/src/Router.php(165): FastRoute\RouteCollector->addRoute('GET', '/', Object(League\Route\Route))
#3 /Users/patrickhochstenbach/Dev/php-solid-server-0.6.2/vendor/league/route/src/Router.php(100): League\Route\Router->prepRoutes(Object(Laminas\Diactoros\ServerRequest))
#4 /Users/patrickhochstenbach/Dev/php-solid-server-0.6.2/web/index.php(222): League\Route\Router->dispatch(Object(Laminas\Diactoros\ServerRequest))
#5 {main}
My installation is OSX:
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.29-to-be-removed-in-future-macOS (cli) (built: Sep 6 2021 05:14:39) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies
This happens both with the current code in the main branch and in the v0.6.2 release.
Thank you for taking the time to report this!
The Solid Server must run on HTTPS according to the spec, but under certain conditions (for instance in development or when behind a proxy) this is not feasible. To make HTTP mode more explicit, the environment flag was changed from ENVIRONMENT to PROXY_MODE in 58110bfd (part of v0.6.0). It looks like the command in the composer.json was not updated to reflect this change.
The composer serve-dev command is basically a simple wrapper for this command:
USERNAME=alice \
PASSWORD=alice123 \
ENVIRONMENT=development \
SERVER_ROOT=http://localhost:8080 \
php -S localhost:8080 -t web/ web/index.php
The PROXY_MODE variable should be present but apparently it is not. 😥
If you run the following (instead of composer serve-dev) things should work as expected:
USERNAME=alice \
PASSWORD=alice123 \
PROXY_MODE=true \
SERVER_ROOT=http://127.0.0.1:8080 \
php -S 127.0.0.1:8080 -t web/ web/index.php
(If you want to see debug information ENVIRONMENT=development should also be added).
Beside this, it looks like the code responsible for the HTTP to HTTPS redirect is incorrect. The code should "just redirect" instead of triggering that warning.
I'll create a separate ticket for that.
Thanks that works for me!