14

I have installed the latest version of Magento 2, everything is working fine frontend, backend and functionality.

I have one issue with bin/magento setup:upgrade command, when I run this command in terminal I get below exception.

[InvalidArgumentException]
There are no commands defined in the "setup" namespace.

Screenshot:

enter image description here

Is there anything I missed during installation or I need to install some package to let it work?

5

15 Answers 15

11

In my case, it worked using sudo

sudo bin/magento setup:upgrade

EDIT 19/02/16

Actually, the "sudo" solution is more a workaround for bad permissions/ownership of Magento files.

If you don't already have a Magento file system owner, create one and add it to the apache group.

adduser magento
passwd magento
    //CentOS
    usermod -g apache magento

    //Ubuntu
    usermod -g www-data magento

//restart apache
    //CentOS
    service httpd restart

    //Ubuntu
    service apache2 restart

Now that you have your user, you can set the ownership and permissions (with root or an user with sudo)

cd /var/www/html/magento2beta/magento2
find . -type d -exec chmod 770 {} \; && sudo find . -type f -exec chmod 660 {} \; && sudo chmod +x bin/magento
//CentOS
chown -R magento:apache .
//Ubuntu
chown -R magento:www-data .

Switch to the magento user

su magento

Now you should be able to run php bin/magento setup:upgrade or any other command with your magento user

4
  • This should be the answer.
    – R T
    Feb 19, 2016 at 5:37
  • 2
    i am using windows. what i have to do for solving this?
    – MaYaNk
    Jun 27, 2016 at 9:56
  • You will also see this error when something is wrong with your custom module, for instance if the module.xml file not is placed in the etc directory and so on. Apr 25, 2018 at 8:43
  • @MaYaNk, to solve this, use linux instead
    – Black
    Sep 2, 2021 at 11:46
9

There are no commands defined is a generic message which hides a real problem.
I have opened the issue stated that Magento 2 should clarify such messages, so please vote for it.
In my cases the problem was with composer.json file and with an extension's module.xml file.
See also:

  • All There are no commands defined issues in the tracker.
  • All There are no commands defined questions on magento.stackexchange.com.
5
  • 1
    Thanks for your reply, did you get any solution to resolve this issue? Nov 26, 2015 at 12:05
  • Of course, just read the links. Nov 26, 2015 at 12:29
  • 1
    @Mage2.PRO please post the final solution here
    – 7ochem
    Nov 27, 2015 at 15:43
  • There is no "the final solution" because it is individual. There are no commands defined just a generic message, it hides a real problem, and the real problem could be different. Nov 27, 2015 at 15:59
  • 1
    @Mage2.PRO There are no commands defined in the "setup" namespace. for this error what i have to do. i am using windows localhost
    – mr. max
    Jun 27, 2016 at 10:01
4

This happens if any XML file defines in etc is not defined correctly. There could be a sequence problem or error in node defining

Open cmd go to your Magento root directory and type the below command.

D:\Server\htdocs\mage2>
D:\Server\htdocs\mage2>php bin/magento list

You will get relative error info.

[Magento\Framework\Exception\LocalizedException]
  Invalid XML in file D:/Server/htdocs/mage2/app/code/Vendor/Module/et
  c/frontend/di.xml:
  Attribute sortOrder redefined
  Line: 4
2

This happens if any XML file defines in etc is not defined correctly. There could be a sequence problem or error in node defining

Open cmd go to your Magento root directory and type the below command.

D:\Server\htdocs\mage2>
D:\Server\htdocs\mage2>php bin/magento list

You will get relative error info.

[Magento\Framework\Exception\LocalizedException]
  Invalid XML in file D:/Server/htdocs/mage2/app/code/Vendor/Module/et
  c/frontend/di.xml:
  Attribute sortOrder redefined
  Line: 4
1

I had this same error and from other answers I am reading on here it is clearly caused by a variety of problems. But mine was caused because my dependency injection file at company/module/etc/di.xml was empty ! ( I had deleted the contents by mistake )

Magento was trying to load the file but it was empty so it was invalid and causing multiple errors including the one in this question

Just thought I would post this incase it saves some else 4 hours of their life !!

1

I have faced the similar issue and in my case, the issue was due to missing config.php in app/etc.

0
0

If you install magento in localhost, you should set permissions 777 for var and pub folder. This issue can resolved

4
  • Thanks for your reply, these folders already have 777 permission Nov 26, 2015 at 13:02
  • And it not woking ?
    – LinoPham
    Nov 26, 2015 at 13:21
  • yes not working Nov 26, 2015 at 13:24
  • Any one got the solution to this? As I run this command then I got another issue/error i.e. pdo_mysql extension is not installed what to do can not figure out.
    – KA9
    Dec 22, 2015 at 12:20
0

I had the same issue and I followed several suggested stupid suggestions to fix the problem like delete my composer.json something like that. But those didn't fix my problem. Today, I faced the problem again and I tried a new approach to trace the problem. All details and screenshot are in my personal blog post http://david.firstbiz.cc/blog_detail.php?id=115 I described my steps here:

1. for CLI, please append "-vvv" and it will display function trace paths
2. try to load any product page and check your web server error log and you will be able to see more details.
3. the class name and the filename should be same (*this is the case I faced)
0

If you get this error just after you were trying to create a module, then make sure that you have added this files in your module. /etc/module.xml

0

It might be permission issue. You can set

chmod -R 777 magento folder permissions.

Just for test and see if it will work. hope this help you.

0

Please check the permission of your magentoDirectory.

$sudo rm -rf var/cache/* generated/code/*

$sudo chmod 777 -R magentoDirectory

$sudo chown -R www-data:www-data magentoDirectory

$php bin/magento setup:di:compile

$php bin/magento cache:clean

0

I could resolve this issue by restarting the server & and provide full permission to files and folder chmod -R 777 . in the local environment! :)

0

To see exactly what the error message is, execute php bin/magento list and look at the error at the bottom.


This problem can also happen if your modules are disabled. I changed to another git branch and suddenly all Magento Modules were disabled.

So I executed php bin/magento module:enable --all to fix it.

Remember to disable unneeded modules after it, for example Magento_Csp or Magento_TwoFactorAuth if you don't need them.


Another option is to manually delete the cache and try again.

rm -r var/cache/*

If this all does not work, then try to reset the permissions as last resort:

sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R :www-data . # Ubuntu
sudo chmod u+x bin/magento

↑ copy paste the whole block and execute it

0

The reason for this error can be seen in the command output: php -f bin/magento.

This will work for most errors like There are no commands defined in the "..." namespace..


A fairly common cause is an error in xml files e.g. VendorName/ModuleName/etc/config.xml.

0

In my case I needed to restart mysql with sudo systemctl restart mysql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.