【问题标题】:server:run Exception There are no commands defined in the "server" namespace服务器:运行异常“服务器”命名空间中没有定义命令
【发布时间】:2017-08-24 07:03:06
【问题描述】:

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

当我运行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

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

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

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

编辑 2

目录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

【问题讨论】:

  • 你用的是哪个php版本?
  • @MaulikSavaliya 我已经更新了我的答案。使用 PHP 7.0.15
  • 你能查一下/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/
  • 您为什么使用 Symfony 的开发版(3.3.0-DEV)以及您是如何安装它的?看起来在 3.2 和 3.3 之间进行了一些重构。现在已经在 AppKernel.php 中添加了 WebServerBundle 以及一些行。如果您需要继续使用最新的开发版本,那么我认为您需要安装一个新项目并迁移您的代码。我猜想处于最前沿的危险之一。 github.com/symfony/symfony/tree/master/src/Symfony/Bundle/…
  • 请考虑您可以简单地将 APP_ENV 更改为 "dev" 以防止出现此错误

标签: php symfony


【解决方案1】:

你可以这样写:

  php -S localhost: 8000 -t public

或者,如果您正在使用 symfony 4.x,请在浏览器中尝试以下命令行:

  symfony server: start

在此开始之前不要忘记安装 symfony CLI:

  https://symfony.com/download

【讨论】:

  • 这对我有用,但删除了文本 php -S localhost:8000 -t public 之间的空格
【解决方案2】:

由于 symfony 4.2 和更新版本,有一些变化,所以你必须这样做:

  • 1:作曲家需要 symfony/web-server-bundle --dev
  • 2: php bin\console --env=dev server:run

【讨论】:

    【解决方案3】:

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

    否则 Symfony 4 将不会在开发模式下运行。

    【讨论】:

    【解决方案4】:

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

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

    然后启动服务器: bin/console --env=dev server:run 0.0.0.0:8005

    【讨论】:

      【解决方案5】:

      删除 env.local 文件(如果有)。

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

      【讨论】:

        【解决方案6】:
        1. 禁用防火墙帮助
        2. 正在运行......composer 清除缓存有助于允许权限
        3. 正在运行......composer req webserver 帮助清除了我在“server”命名空间中定义的命令

        【讨论】:

          【解决方案7】:

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

          所以你需要这个包:

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

          在您的 AppKernel 中

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

          更多信息:check here

          【讨论】:

            【解决方案8】:

            对于 symfony 4 和更多你应该输入php -S 127.0.0.1:8000 -t public 来启动服务器

            【讨论】:

              【解决方案9】:

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

              【讨论】:

              • 如果你能在这里举一些例子就好了。
              【解决方案10】:

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

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

              【讨论】:

              • 正确的命令是:composer require symfony/web-server-bundle --dev
              • 这将安装在开发环境中,因此在bin/console 中可能不可见。如果发生这种情况,请使用-e=dev 参数运行(例如bin/console -e=dev server:run)或在.env 文件中添加APP_ENV=dev
              • 您可能需要指定版本:composer require symfony/web-server-bundle --dev ^4.4.5
              【解决方案11】:

              类型:

              php bin/控制台

              您将看到所有允许的命令。

              如果你想使用服务器命令,你应该在你的项目中安装它:

              composer 需要服务器 --dev

              再次运行

              php bin/控制台

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

              【讨论】:

                【解决方案12】:

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

                我不做任何承诺,但尝试更新 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();
                        }
                    }
                

                我没有一个好的测试项目可以尝试,但至少命令应该会显示出来。

                如果有人想知道,我所做的只是安装一个新的开发项目并四处寻找。

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

                我也找到了这个,但它没有提到需要更新 AppKernel.php http://symfony.com/blog/new-in-symfony-3-3-webserverbundle

                来自升级指南:https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.3.md

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

                只要你的 composer.json 中包含 symfony/symfony,那么就不需要添加 web 服务器包。只需要调整AppKernel文件即可。

                【讨论】:

                  【解决方案13】:

                  你必须执行这个命令:

                  composer req webserver
                  

                  【讨论】:

                  • 在 Symfony 3.3 和 PHP 7.1 上帮助我,能够使用 server:run
                  猜你喜欢
                  • 2023-03-16
                  • 1970-01-01
                  • 1970-01-01
                  • 2022-01-12
                  • 2017-10-29
                  • 1970-01-01
                  • 1970-01-01
                  • 2020-11-28
                  • 2010-10-12
                  相关资源
                  最近更新 更多