11

I have installed latest version of Megento 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 any thing I missed during installation or I need to install some package to let it working?

10 Answers 10

9

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 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+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

  • This should be the answer. – R T Feb 19 '16 at 5:37
  • 2
    i am using windows. what i have to do for solving this? – MaYaNk Jun 27 '16 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. – Cyclonecode Apr 25 '18 at 8:43
7

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.
  • 1
    Thanks for your reply, did you get any solution to resolve this issue? – Deepak Mankotia Nov 26 '15 at 12:05
  • Of course, just read the links. – Mage2.PRO Nov 26 '15 at 12:29
  • 1
    @Mage2.PRO please post the final solution here – 7ochem Nov 27 '15 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. – Mage2.PRO Nov 27 '15 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 '16 at 10:01
3

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

Open cmd go to your magento root directory and type 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 your any xml file defines in etc is not defined correctly. There could be sequence problem or error in node defining

Open cmd go to your magento root directory and type 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

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

  • Thanks for your reply, these folders already have 777 permission – Deepak Mankotia Nov 26 '15 at 13:02
  • And it not woking ? – Bill Nov 26 '15 at 13:21
  • yes not working – Deepak Mankotia Nov 26 '15 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 '15 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

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 !!

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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