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

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.
When I run php bin/console command I egt the following output. Which does't show any server: commands.
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/symfony and composer update but it still doesn't show.
Is there anything else that I can try?
Edit below is my php info from 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
the directory vendor\symfon\symfony\src\Symfony\Bundle\FrameworkBundle\Command exists and contains the following files
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

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.

run this command before starting the server.
composer require symfony/web-server-bundle --dev

you must execute this command:
composer req webserver

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.

As #Barh says, you must have APP_ENV=dev in your .env file.
Otherwise Symfony 4 will not be runnable in dev mode.

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

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

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

upgrading from symfony <3.3 to symfony >3.3 will cause this problem because the web server was extracted out to a separate bundle.
so you'll need to require this bundle:
composer require symfony/web-server-bundle --dev
and in your AppKernel
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
for more info: check here

I had same issue on Symfony 4 after switching in .env to prod. Some commands are not visible on prod.
You either need to swap to dev or:
bin/console --env=dev
And so to start server:
bin/console --env=dev server:run 0.0.0.0:8005

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

Disabling firewall help
running......composer clear cache helped in allowing permission
running......composer req webserver helped clear my commands defined in the "server" namespace

Remove env.local file if you've it.
Reson:
Because server:run is not executing on production environment

Related

How do I run symfony console?

Everywhere I look in the Symfony documentation for Symfony 4.2, it says that to clear the cache, I run:
php bin/console cache:clear
However, this bin/console is a relative path. I can't find bin/console anywhere. I've done a find on my composer vendor directory. Nothing.
Where is bin/console?
I'm running php 7.2.
Symfony 4.x structures in like this (From CoderSkills)
If you don't have the same after your installation, remove your project folder and create a new ones by running composer create-project symfony/website-skeleton myNewProject
Here is a guide to start a new Symfony project

The Symfone "doctrine:fixtures:load" command missing

I have Symfony 3.1 project with Doctrine and
doctrine/doctrine-fixtures-bundle and
doctrine/data-fixtures installed.
However, when i run a console command
php bin/console doctrine:fixtures:load
i get a message saying that there are no commands defined in the doctrine:fixtures namespace.
The class Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand exists.
Please suggest how to fix that.
Run first php bin/console and see if the command appear in the list.
If it doesn't, then you have to load the bundle in the AppKernel.php
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
php bin/console default environment is PROD
and fixtures proper installation is require-dev
so proper function call is:
php bin/console --env=dev doctrine:fixtures:load
Also rm -rf var/cache worked for me (after the bundle registration)
Data Fixtures Mechanism requires a special bundle. It is not included in Sf by default.
Check: http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html
and install it.
Bundle called DoctrineFixturesBundle. You can also find there many useful information how to use fixtures.
So that why you've got message "Command is not defined".

Symfony2.7.1 fresh installation. Failed to load resource

Symfony2 developers:
Recently, I am planning to get familiar with Symfony2, using it as api project. Current version is v2.7.1.
I already have apache installed as my local environment. So the installation root directory is:
//localhost/symfony
So I followed official guide to install it. Everything looks fine after installation. But when I view the page in development environment (app_dev.php).
//localhost/symfony/web/app_dev.php
Page content display as expected, but not styled. Then I open console and find some 404 response as follows:
Failed to load resource
//localhost/symfony/web/bundles/framework/css/structure.css
//localhost/symfony/web/bundles/framework/css/body.css
//localhost/symfony/web/bundles/framework/css/exception.css
//localhost/symfony/web/app_dev.php
//localhost/symfony/web/bundles/framework/css/structure.css
//localhost/symfony/web/bundles/framework/css/body.css
//localhost/symfony/web/bundles/framework/css/exception.css
I looked into project/web/bundles directory, found nothing inside but two empty file.
framework and sensiodistribution.
Fresh installation without any config change. I got this problem. Could you guys give some explanation why it occurs. Otherwise I didn't get the full package?
Do I miss those files inside project/web/bundles?
If the case in which i missed those file. So could you send me an archive file on current version 2.7.1?
You must run the command app/console assets:install to generate symlinks (or files) in /web/bundles
If these files exists then you probably have problem with URL Rewriting check your .htaccess or configure your host. You can also use command php app/console server:start and check there if it works
You can run composer install to install all necessary bundles and libraries and probably composer.json has defined postinstall commands.
If you use assetic then you can try to run php app/console assetic:dump more on http://symfony.com/doc/current/cookbook/assetic/asset_management.html
In Symfony 2.6 you have new asset manager read more on http://symfony.com/blog/new-in-symfony-2-6-smarter-assets-install-command
php app/console assets:install or php app/console assets:install --symlink
for Symfony 3.x the directory changed from app to bin so commands are:
php bin/console assets:install or php bin/console assets:install --symlink
Since I landed here from a Symfony 3 search this might be useful for Symfony 3 users having the same problem
Run php bin/console assets:install at the project root

Symfony2 on Heroku (official buildpack) - how to dump assets?

I have a problem with Symfony assets on heroku (official php buildpack).
My code is based on Symfony 2.5 with new 3.0 folder structure, and it's using one local js and css file (the rest is loaded via cdn).
Those files are loaded exactly as described here: http://symfony.com/doc/current/cookbook/assetic/asset_management.html.
On dev environment everything is ok, but when i change env to prod then i need to do assetic:dump to force symfony dump my assets files into web/css|js folders. I made test on my local machine (switching env to prod) and everything is ok. The problem is with heroku, and its ephemeral filesystem:
When I try to run assetic:dump --env=prod by composer post-install-cmd, then deploy finish with successs, but every request ends up with:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught exception
'InvalidArgumentException' with message
'The file "/tmp/build_012d99e7-a14a-4626-afec-3ded3d4baeec/app/config/routing.yml"
When i deploy app without assetic:dump then of course my local css and js files are not available :/
Maybe there is some other script hook i can use to dump my assets?
Any ideas? Anyone succeded with assetic:dump on heroku and official php buildpack?
PHP and Symfony support has been revamped a lot in the last months, check out these links:
http://symfony.com/doc/current/cookbook/deployment/heroku.html
https://devcenter.heroku.com/articles/getting-started-with-php
https://devcenter.heroku.com/articles/php-support
https://devcenter.heroku.com/articles/getting-started-with-symfony2
What's most important:
Set an environment variable for SYMFONY_ENV
The value of SYMFONY_ENV is used to define the environment for CLI commands. So you don't have to fiddle about something like --env=prod in you custom commands. Composer hooks from composer.json (like post-install-cmd) are automatically executed with the defined environment. Please note: Set it to something different than dev. A dev environment may not work well on Heroku because Composer's dev dependencies (require-dev) are not installed. This is due to the --no-dev flag during the composer install on Heroku. For example, in the Symfony Standard Edition) the SensioGeneratorBundle never gets installed (if you do not move it to the require key in composer.json) and the dev environment won't work.
Error on /tmp path
The mentioned error should have been fixed with https://github.com/symfony/symfony/pull/12784. See also https://github.com/heroku/heroku-buildpack-php/issues/64.
Custom commands during deployment
Custom commands like assetic:dump can be placed in composer.json's script section under the compile key:
{
"scripts": {
"compile": [
"app/console assetic:dump"
]
}
}
See also https://devcenter.heroku.com/articles/php-support#custom-compile-step. Environment is taken from the above mentioned SYMFONY_ENV environment variable.

Steps for going live - Symfony2

I've been working on my website for some time now and I am now ready to push this brand new project to live.
I have already already read this link on Symfony2 with regards to what should be done, but I still think it is missing some details. For example, it talks nothing about some of the commands that I run to get the site to work on live.
Currently this is what I would like to do to get this to work on live:
php composer.phar install --no-dev --optimize-autoloader --no-scripts
rm -rf app/cache/*
php app/console assetic:dump --env=prod --no-debug
php app/console assets:install web --symlink --env=prod
Is there anything else that needs to be done, for example, I don't want live to be able to execute my fixtures, nor do I want any users to be able to go to www.mysite.com/app_dev.php
Check out How to deploy a Symfony2 application.
Refer to link above. The typical steps taken while deploying a Symfony2 application include:
Upload your modified code to the live server;
Update your vendor dependencies (typically done via Composer, and may be done before uploading);
Running database migrations or similar tasks to update any changed data structures;
Clearing (and perhaps more importantly, warming up) your cache.
Common Post-Deployment Tasks
Configure your app/config/parameters.yml file
Update your vendors
$ php composer.phar install --no-dev --optimize-autoloader
Clear your Symfony cache
$ php app/console cache:clear --env=prod --no-debug
Dump your Assetic assets
$ php app/console assetic:dump --env=prod --no-debug
Other things!
There may be lots of other things that you need to do, depending on your setup:
Running any database migrations
Clearing your APC cache
Running assets:install (taken care of already in composer.phar install)
Add/edit CRON jobs
Pushing assets to a CDN
...
take a look at capifony (https://github.com/everzet/capifony). Unfortunately the Website (http://capifony.org) is currently down..
The best solution to me is to have your project in a versionning system like git or svn without the vendors dir of course ...
This way, your simply have to do :
1) git clone your project into the prod dir
2) php composer.phar install to install your vendors
2b) create the mysql user with correct login and password according to your parameters.yml
3) php app/console doctrine:database:create to create your database with the credentials you set up in mysql
4) php app/console doctrine:schema:update --force to perform the database tables creation
5) testing the project :)
If you are not using a versionning system just upload your project to your server with an ftp software without the vendors directory ( it will be feeded by step 2) then perform 3rd , 4th and 5th steps !
you now should be able to reach you project through you domain url .

Categories