当我使用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/symfony
和composer update
来修复它,但它仍然无法显示。
还有什么我可以尝试的吗?
以下编辑是我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
编辑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
答案 0 :(得分:44)
正如我在评论中提到的,在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
服务器:运行,服务器:启动,服务器:停止和服务器:状态控制台命令已移至专用捆绑包。在composer.json中需要symfony / web-server-bundle并在AppKernel中注册Symfony \ Bundle \ WebServerBundle \ WebServerBundle 以使用它们。
只要您的composer.json中包含symfony / symfony,就无需向其添加Web服务器包。只需要调整AppKernel文件。
答案 1 :(得分:15)
在启动服务器之前运行此命令。
composer require symfony/web-server-bundle --dev
答案 2 :(得分:14)
你必须执行这个命令:
composer req webserver
答案 3 :(得分:6)
类型:
php bin / console
您将看到所有允许的命令。
如果您想使用服务器命令,您应该在项目中输入:
composer require server --dev
再次跑步
php bin / console
你应该能够看到并使用它。
答案 4 :(得分:4)
验证是否在环境中设置了正确的APP_ENV。 就我而言,这很关键。
答案 5 :(得分:1)
如@Barh所说,您的APP_ENV=dev
文件中必须有.env
。
否则Symfony 4将不会在开发模式下运行。
答案 6 :(得分:1)
从symfony <3.3升级到symfony> 3.3会导致此问题,因为Web服务器已提取到单独的包中。
所以您需要此捆绑包:
composer require symfony/web-server-bundle --dev
并在您的AppKernel中
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
有关更多信息:check here
答案 7 :(得分:1)
自symfony 4.2及更高版本开始,发生了一些变化,因此要工作,您必须这样做:
答案 8 :(得分:1)
您可以输入以下内容:
php -S localhost: 8000 -t public
或者如果您正在使用symfony 4.x,请在浏览器中尝试以下命令行:
symfony server: start
在此之前,请不要忘记安装symfony CLI:
https://symfony.com/download
答案 9 :(得分:0)
答案 10 :(得分:0)
如果有,请删除env.local文件。
Reson: 因为server:run不在生产环境中执行
答案 11 :(得分:0)
在将.env
切换到prod后,我在Symfony 4上遇到了同样的问题。有些命令在产品上不可见。
您需要交换为dev或:
bin/console --env=dev
然后启动服务器:
bin/console --env=dev server:run 0.0.0.0:8005
答案 12 :(得分:-1)
对于symfony 4及更高版本,您应该键入php -S 127.0.0.1:8000 -t public
来启动服务器