↑ ↓ select, Enter open, Esc close

Run WP-CLI as the Plesk subscription user instead of root

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
root@server
runuser -u webuser -- wp plugin list --path=/var/www/vhosts/example.com/httpdocs

Starts WP-CLI as the subscription’s system user, who owns the files under /var/www/vhosts/<domain>. This keeps newly created files such as uploads, plugins or caches under the right owner, so PHP-FPM can still write to them. stat -c %U on the httpdocs directory shows the subscription user.

Note: The alternative --allow-root works, but it runs plugin code with root privileges and leaves root-owned files behind. It should remain the exception.

Open question before approval: Prüfen, ob wp im PATH von runuser liegt (sonst vollen Pfad wie /usr/local/bin/wp angeben) und ob WP-CLI ohne HOME-Verzeichnis-Schreibrechte des Abo-Benutzers sauber läuft.

Also searched as

  • wp cli running as root warning
  • wp cli allow-root plesk
  • run wp cli as correct user

Related one-liners

All in WP-CLI

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.