bash - how to show files in current directory with embedded php webserver (as command line) ← (PHP)

one text

Solution:

Replace "./" from the assignment of variable $directory with the complete path of the directory you want to serve. Or, even better, change it to:

$directory = $_SERVER['DOCUMENT_ROOT'].'/';

to serve the path you provide as argument to -t in the command line.

Put index.php wherever you want in the file system and add its location (with complete path) to the end of the php command line.

If, for example, you save it as /home/erik/index.php, start PHP as:

php -S 0.0.0.0:8000 -t /home/erik/web /home/erik/index.php

PHP will use the script as a router. It will run it on every request and you can change it to interpret the request ($_GET[], $_SERVER[]) and generate different output, depending of the requested path and query string.

Source