Skip to content

Commit

Permalink
built-in server: exit when docroot does not exist
Browse files Browse the repository at this point in the history
When the server:run command is run with an invalid document root
directory (for example, when being in the app directory and not
changing the document root to ../web/), the command crashes on Windows
with a 267 exit code. On Linux, the server starts but just publishes
internal server errors.
  • Loading branch information
xabbuh committed Aug 2, 2014
1 parent cd005e6 commit f143254
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php
Expand Up @@ -81,6 +81,14 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$documentRoot = $input->getOption('docroot');

if (!is_dir($documentRoot)) {
$output->writeln(sprintf('<error>The given document root directory "%s" does not exist</error>', $documentRoot));

return 1;
}

$env = $this->getContainer()->getParameter('kernel.environment');

if ('prod' === $env) {
Expand All @@ -96,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));

$builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router));
$builder->setWorkingDirectory($input->getOption('docroot'));
$builder->setWorkingDirectory($documentRoot);
$builder->setTimeout(null);
$builder->getProcess()->run(function ($type, $buffer) use ($output) {
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
Expand Down

0 comments on commit f143254

Please sign in to comment.