I am trying to run indexer. but when i enter command CLI shows this error http://prntscr.com/ntzzlt

also i always need to give permission to generated folder, Pub folder and Var Folder after running Setup Upgrade

sudo chmod 777 -R generated, pub, var


2 Answers 2


sudo (Super User DO) command in Linux is generally used as a prefix of some command that only superuser are allowed to run.

If you prefix “sudo” with any command, it will run that command with elevated privileges or in other words allow a user with proper permissions to execute a command as another user, such as the superuser. This is the equivalent of “run as administrator” option in Windows. The option of sudo lets us have multiple administrators.

Using sudo Try To Reindex :-

 sudo php bin/magento indexer:reindex
  • i need permanent solution, why i need to use sudo always?
    – sudo55
    Commented May 27, 2019 at 15:39
  • It stands for “super user do!”..it will run that command with elevated privileges. Elevated privileges are required to perform certain administrative tasks. Commented May 27, 2019 at 15:40
  • understand ???? Commented May 27, 2019 at 15:43
  • yes, but there must be any permanent sol,
    – sudo55
    Commented May 27, 2019 at 15:47
  • yes its per solution Commented May 27, 2019 at 15:48

Execute these commands as a root user

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +

find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +

Set the ownership to Magento user and web user using

sudo chown -R <Magento user>:<web server group> .

The error which you are facing is due to wrong ownership. If you navigate to the specified folder and run ll you can find the ownership for the file is assigned to root user which is preventing from removing the generated files as Magento user.

Please at any case don't give 777 permission if so please revert it back.

Don't run any command as root user as it might cause the new static files to be created with root ownership which might prevent web user to access such files forcing you to provide 777 permission. So run Magento commands as Magento user.

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