#TIL : Run built-in server via Docker

Docker is the fast and clean way to run Linux programs.

We can run a PHP project via PHP built-in server and Docker.

1
docker run -it -p 8080:8080 -v `pwd`:/code php:7 php -S 0.0.0.0:8080 -t /code/web /code/web/server.php

With server.php content is

1
2
3
4
5
6
7
8
9
10
11
<?php

$filename = __DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
return false;

}

// Run application below
$app = new Application();
$app->run();

Comments