I installed this package on WP-CLI. When I run wp login create in bash it works fine, but when I run exec("wp login create") in PHP script WP-CLI return this error:

Error: 'login' is not a registered wp command. See 'wp help' for available commands.

Did you mean 'plugin'?

I checked the user from exec("whoami") and it's the same. How can I find the problem?

EDIT

when I run wp package list in PHP it returns:

Error: Composer directory '/.wp-cli/packages' for packages couldn't be created: mkdir(): Permission denied

  • 1
    You might get different result because you are running the commands under different user. – Thomas Moors Oct 22 at 12:40
  • but I run the command in bash with a user named admin@server and when I run exec("whoami") in PHP it says admin. can you explain how are they different? – Ali Sh Oct 23 at 4:57
  • is the group also the same? – Thomas Moors Oct 23 at 7:31
  • yes it is the same. I checked with hostname command. – Ali Sh Oct 23 at 8:17
up vote 1 down vote accepted

According to Alain Schlesser in wordpress slack:

The folder that the packages are installed into is set to use your server user's home folder. When you try to execute this command from PHP, however, it is being executed by the webserver's user, which probably has a different home folder, and the package is not installed in there.

You can either load the package manually as part of the system (requiring it in the site's Composer stack, for example), or set the package folder to a location that is shared by both your user and your webserver (and reinstall it afterwards).

You can set the packages folder with the WP_CLI_PACKAGES_DIR environment variable: https://make.wordpress.org/cli/handbook/config/#environment-variables

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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