Sample command:
drush cc all
works, but this:
sudo drush cc all
gives me:
sudo: drush: command not found
Why? How to fix this?
Sample command:
drush cc all
works, but this:
sudo drush cc all
gives me:
sudo: drush: command not found
Why? How to fix this?
When you sudo, you get a preconfigured $PATH, which is (supposed to be) something like the root user's default path. Your program is not in that list of directories identified by $PATH.
See for example
sudo preserve $PATH?PATH)sudo tries to be safe when executing external commands.
There are two distinct ways to deal with environment variables. By default, the
env_resetsudoers option is enabled. This causes commands to be executed with a minimal environment containingTERM,PATH,HOME,SHELL,LOGNAME,USERandUSERNAMEin addition to variables from the invoking process permitted by theenv_checkandenv_keepsudoers options. There is effectively a whitelist for environment variables.
If you cannot configure sudo to preserve your $PATH, the usual workaround is to specify the complete pathname of the program. That may not work well with scripts that call other executables in the (not-accessed) directory.
You should specify the full path. It's also more secure; it you don't specify the path, it's conceivable that an attacker could create another program that will be run with root permissions.
Also, you need to put a line in /etc/sudoers to allow it. man sudoers for the syntax, it's way too much to put here.