server:run Exception There are no commands defined in the “server” namespace

前端 未结 13 1389
甜味超标
甜味超标 2020-12-25 10:17

When I run the server using php bin/console server:run I get the following error. There are no commands defined in the \"server\" namespace.

<
13条回答
  •  借酒劲吻你
    2020-12-25 10:39

    As I mentioned in my comment, in S3.3 the server commands have been moved to their own WebServerBundle. Some editing of AppKernel.php is required to activate the bundle. I suspect that many other developers might run into this once 3.3 is actually released and people try upgrading.

    I make no promises but try updating AppKernel.php with:

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
    
            if ('dev' === $this->getEnvironment()) {
                $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
                $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
            }
        }
    

    I don't have a good test project to try it on but at least the commands should show up.

    And in case anyone is wondering, all I did was to install a fresh development project and poked around a bit.

    composer create-project symfony/framework-standard-edition s33 "3.3.*" --stability=dev
    

    I also found this but it does not mention the need to update AppKernel.php http://symfony.com/blog/new-in-symfony-3-3-webserverbundle

    From the upgrade guide: https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.3.md

    The server:run, server:start, server:stop and server:status console commands have been moved to a dedicated bundle. Require symfony/web-server-bundle in your composer.json and register Symfony\Bundle\WebServerBundle\WebServerBundle in your AppKernel to use them.

    As long as your composer.json has symfony/symfony in it then there is no need to add the web server bundle to it. Just need to adjust the AppKernel file.

提交回复
热议问题