function ServerCommand::execute

Same name in other branches
  1. 9 core/lib/Drupal/Core/Command/ServerCommand.php \Drupal\Core\Command\ServerCommand::execute()
  2. 8.9.x core/lib/Drupal/Core/Command/ServerCommand.php \Drupal\Core\Command\ServerCommand::execute()
  3. 11.x core/lib/Drupal/Core/Command/ServerCommand.php \Drupal\Core\Command\ServerCommand::execute()

File

core/lib/Drupal/Core/Command/ServerCommand.php, line 61

Class

ServerCommand
Runs the PHP webserver for a Drupal site for local testing/development.

Namespace

Drupal\Core\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
    $io = new SymfonyStyle($input, $output);
    $host = $input->getOption('host');
    $port = $input->getOption('port');
    if (!$port) {
        $port = $this->findAvailablePort($host);
    }
    if (!$port) {
        $io->getErrorStyle()
            ->error('Unable to automatically determine a port. Use the --port to hardcode an available port.');
    }
    try {
        $kernel = $this->boot();
    } catch (ConnectionNotDefinedException $e) {
        $io->getErrorStyle()
            ->error("No installation found. Use the 'install' command.");
        return 1;
    }
    return $this->start($host, $port, $kernel, $input, $io);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.