php 服务器:运行异常在“服务器”命名空间中没有定义命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43116427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:46:37  来源:igfitidea点击:

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

phpsymfony

提问by Sarah Richardson

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

当我使用运行服务器时php bin/console server:run,出现以下错误。 There are no commands defined in the "server" namespace.

When I run php bin/consolecommand I egt the following output. Which does't show any server: commands.

当我运行php bin/console命令时,我得到以下输出。这不显示任何服务器:命令。

Symfony 3.3.0-DEV (kernel: app, env: dev, debug: true)

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -e, --env=ENV         The environment name [default: "dev"]
      --no-debug        Switches off debug mode
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                                   Displays information about the current project
  help                                    Displays help for a command
  list                                    Lists commands
 app
  app:download-beameemail                 download beame emails.
  app:download-businessunits              download businessunits.
  app:download-drivers                    download drivers.
  app:download-fleets                     download fleets.
  app:download-fmpositions                download fm_positions.
  app:download-fmtrips                    download fm_trips.
  app:download-fmunits                    download fm_units.
  app:download-skypositions               download skytrack_positions.
  app:download-skyunits                   download skytrack_units.
  app:download-vehicles                   download vehicles.
 assets
  assets:install                          Installs bundles web assets under a public web directory
 cache
  cache:clear                             Clears the cache
  cache:pool:clear                        Clears cache pools
  cache:warmup                            Warms up an empty cache
 config
  config:dump-reference                   Dumps the default configuration for an extension
 debug
  debug:config                            Dumps the current configuration for an extension
  debug:container                         Displays current services for an application
  debug:event-dispatcher                  Displays configured listeners for an application
  debug:router                            Displays current routes for an application
  debug:swiftmailer                       [swiftmailer:debug] Displays current mailers for an application
  debug:translation                       Displays translation messages information
  debug:twig                              Shows a list of twig functions, filters, globals and tests
 doctrine
  doctrine:cache:clear-collection-region  Clear a second-level cache collection region.
  doctrine:cache:clear-entity-region      Clear a second-level cache entity region.
  doctrine:cache:clear-metadata           Clears all metadata cache for an entity manager
  doctrine:cache:clear-query              Clears all query cache for an entity manager
  doctrine:cache:clear-query-region       Clear a second-level cache query region.
  doctrine:cache:clear-result             Clears result cache for an entity manager
  doctrine:database:create                Creates the configured database
  doctrine:database:drop                  Drops the configured database
  doctrine:database:import                Import SQL file(s) directly to Database.
  doctrine:ensure-production-settings     Verify that Doctrine is properly configured for a production environment.
  doctrine:generate:crud                  [generate:doctrine:crud] Generates a CRUD based on a Doctrine entity
  doctrine:generate:entities              [generate:doctrine:entities] Generates entity classes and method stubs from your mapping information
  doctrine:generate:entity                [generate:doctrine:entity] Generates a new Doctrine entity inside a bundle
  doctrine:generate:form                  [generate:doctrine:form] Generates a form type class based on a Doctrine entity
  doctrine:mapping:convert                [orm:convert:mapping] Convert mapping information between supported formats.
  doctrine:mapping:import                 Imports mapping information from an existing database
  doctrine:mapping:info                   
  doctrine:query:dql                      Executes arbitrary DQL directly from the command line.
  doctrine:query:sql                      Executes arbitrary SQL directly from the command line.
  doctrine:schema:create                  Executes (or dumps) the SQL needed to generate the database schema
  doctrine:schema:drop                    Executes (or dumps) the SQL needed to drop the current database schema
  doctrine:schema:update                  Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata.
  doctrine:schema:validate                Validate the mapping files.
 fos
  fos:js-routing:debug                    Displays currently exposed routes for an application
  fos:js-routing:dump                     Dumps exposed routes to the filesystem
 generate
  generate:bundle                         Generates a bundle
  generate:command                        Generates a console command
  generate:controller                     Generates a controller
 lint
  lint:twig                               Lints a template and outputs encountered errors
  lint:xliff                              Lints a XLIFF file and outputs encountered errors
  lint:yaml                               Lints a file and outputs encountered errors
 router
  router:match                            Helps debug routes by simulating a path info match
 security
  security:check                          Checks security issues in your project dependencies
  security:encode-password                Encodes a password.
 swiftmailer
  swiftmailer:email:send                  Send simple email message
  swiftmailer:spool:send                  Sends emails from the spool
 translation
  translation:update                      Updates the translation file

I've tried to fix it by running composer require symfony/symfonyand composer updatebut it still doesn't show. Is there anything else that I can try?

我试图通过运行来修复它composer require symfony/symfonycomposer update但它仍然没有显示。还有什么我可以尝试的吗?

Edit below is my php info from php -version

下面编辑是我的php信息 php -version

PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.15-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

EDIT 2

编辑 2

the directory vendor\symfon\symfony\src\Symfony\Bundle\FrameworkBundle\Commandexists and contains the following files

该目录vendor\symfon\symfony\src\Symfony\Bundle\FrameworkBundle\Command存在并包含以下文件

AboutCommand.php
AbstractConfigCommand.php
AssetsInstallCommand.php
CacheClearCommand.php
CachePoolClearCommand.php
CacheWarmupCommand.php
ConfigDebugCommand.php
ConfigDumpReferenceCommand.php
ContainerAwareCommand.php
ContainerDebugCommand.php
EventDispatcherDebugCommand.php
RouterDebugCommand.php
RouterMatchCommand.php
TranslationDebugCommand.php
TranslationUpdateCommand.php
WorkflowDumpCommand.php
XliffLintCommand.php
YamlLintCommand.php

回答by Cerad

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.

正如我在评论中提到的,在 S3.3 中,服务器命令已移至它们自己的 WebServerBundle。需要对 AppKernel.php 进行一些编辑才能激活该包。我怀疑一旦 3.3 真正发布并且人们尝试升级,许多其他开发人员可能会遇到这个问题。

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

我不做任何承诺,但尝试使用以下内容更新 AppKernel.php:

    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

我也发现了这个,但它没有提到需要更新 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

从升级指南: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\WebServerBundlein your AppKernel to use them.

server:run、server:start、server:stop 和 server:status 控制台命令已移至专用包中。在 composer.json 中需要 symfony/web-server-bundle 并在 AppKernel 中注册 Symfony\Bundle\WebServerBundle\WebServerBundle以使用它们。

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.

只要你的 composer.json 中有 symfony/symfony 就没有必要向其中添加 web 服务器包。只需要调整 AppKernel 文件。

回答by Sarath Kumar

run this command before starting the server.

在启动服务器之前运行此命令。

composer require symfony/web-server-bundle --dev

回答by Israel Bazan

you must execute this command:

你必须执行这个命令:

composer req webserver

回答by Zenit

Type:

类型:

php bin/console

php bin/控制台

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

作曲家需要服务器 --dev

run again

再次运行

php bin/console

php bin/控制台

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

你应该能够看到它并使用它。

回答by Barh

Verify that the correct APP_ENV is set in the environment. In my case, it was critical.

验证是否在环境中设置了正确的 APP_ENV。就我而言,这很关键。

回答by Dinath

As @Barh says, you must have APP_ENV=devin your .envfile.

正如@Barh 所说,您APP_ENV=dev.env文件中必须有。

Otherwise Symfony 4 will notbe runnable in dev mode.

否则 Symfony 4将无法在开发模式下运行。

回答by Sadik anass

upgrading from symfony <3.3 to symfony >3.3 will cause this problem because the web server was extracted out to a separate bundle.

从 symfony <3.3 升级到 symfony >3.3 会导致这个问题,因为 web 服务器被提取到一个单独的包中。

so you'll need to require this bundle:

所以你需要这个包:

composer require symfony/web-server-bundle --dev

and in your AppKernel

并在您的 AppKernel 中

 if ('dev' === $this->getEnvironment()) {
        $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
    }

for more info: check here

欲了解更多信息:请查看此处

回答by Fouad Teneson

  1. Disabling firewall help
  2. running......composer clear cache helped in allowing permission
  3. running......composer req webserver helped clear my commands defined in the "server" namespace
  1. 禁用防火墙帮助
  2. 正在运行......作曲家清除缓存有助于允许权限
  3. 正在运行......composer req webserver 帮助清除了我在“server”命名空间中定义的命令

回答by symi khan

Remove env.local file if you've it.

如果你有 env.local 文件,请删除它。

Reson: Because server:run is not executing on production environment

原因:因为 server:run 没有在生产环境中执行

回答by Volmarg Reiso

I had same issue on Symfony 4 after switching in .envto prod. Some commands are not visible on prod.

切换.env到 prod后,我在 Symfony 4 上遇到了同样的问题。某些命令在 prod 上不可见。

You either need to swap to dev or: bin/console --env=dev

您需要切换到 dev 或: bin/console --env=dev

And so to start server: bin/console --env=dev server:run 0.0.0.0:8005

所以要启动服务器: bin/console --env=dev server:run 0.0.0.0:8005