public function runServer()
    {
        $router = $this->drupalDir . '/.ht.router.php';
        if (!file_exists($router)) {
            $this->createFile(
                $router,
                file_get_contents(__DIR__ . '/.ht.router.php')
            );
        }

        $uri = parse_url($this->baseUrl);

        $this->serverProcess = ProcessBuilder::create()
            ->setPrefix('exec')
            ->add($this->phpBin)
            ->add('-S')
            ->add(sprintf('%s:%s', $uri['host'], $uri['port']))
            ->add($router)
            ->setWorkingDirectory($this->drupalDir)
            ->getProcess();

        $this->serverProcess->start();

        sleep(1);

        if (!$this->serverProcess->isRunning()) {
            throw new RuntimeException('PHP built-in server process terminated immediately');
        }

        // Also trap fatal errors to make sure running processes are terminated.
        register_shutdown_function([$this, 'stopServer']);
    }