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

前端 未结 13 1379
甜味超标
甜味超标 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:35

    As @Barh says, you must have APP_ENV=dev in your .env file.

    Otherwise Symfony 4 will not be runnable in dev mode.

    0 讨论(0)
  • 2020-12-25 10:38

    For symfony 4 and more you should type php -S 127.0.0.1:8000 -t public to start the server

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-25 10:41

    you can put this:

      php -S localhost: 8000 -t public
    

    or if you are working on symfony 4.x try this command line in your browser:

      symfony server: start
    

    don't forget to install symfony CLI before this start from this:

      https://symfony.com/download
    
    0 讨论(0)
  • 2020-12-25 10:43

    Type:

    php bin/console

    You'll see all the commands allowed.

    If you want to use the server commands you should install it typing on your project:

    composer require server --dev

    run again

    php bin/console

    and you should be able to see it and use it.

    0 讨论(0)
  • 2020-12-25 10:47

    Since symfony 4.2 and newer, theres is some changes so, to works you have to do this :

    • 1: composer require symfony/web-server-bundle --dev
    • 2: php bin\console --env=dev server:run
    0 讨论(0)
提交回复
热议问题