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

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.
Putindex.php
wherever you want in the file system and add its location (with complete path) to the end of thephp
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.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: target class [commandmakecommand] does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.