Written by James McDonald

February 17, 2022

I have a script that runs the wp cli to loop through and update the WordPress themes, plugins & core for a number of sites. Each site has different linux user ownership.

The problem I am seeing is an error message of Permission denied when running

sudo -u $OWNER $WP --path=$WP_DIR theme update --all
sudo -u $OWNER $WP --path=$WP_DIR plugin update --all
sudo -u $OWNER $WP --path=$WP_DIR core update
Enabling Maintenance mode...
Downloading update from https://downloads.wordpress.org/plugin/go-live-update-urls.6.3.7.zip...
PHP Warning:  rename(/tmp/go-live-update-urls.6.3.7-JImPud.tmp,go-live-update-urls.6.3.7.zip): Permission denied in /var/www/myuser/web/wp-admin/includes/file.php on line 1201
Warning: rename(/tmp/go-live-update-urls.6.3.7-JImPud.tmp,go-live-update-urls.6.3.7.zip): Permission denied in /var/www/myuser/web/wp-admin/includes/file.php on line 1201
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Disabling Maintenance mode...

I have managed to duplicate the problem with a test script. Basically it is a permission denied because the target directory of the rename operation is non-writeable by the user running the script.


$from = '/tmp/test.txt';
# create the file
file_put_contents($from,  "Hello World");

$to= 'newName.txt';
# try rename it
var_dump(rename($from, $to));
# I am in my home directory
cd /home/myuser

# I am trying to run the script as another user
sudo -u otheruser php test_rename.php

# because the rename to location is myuser home directory 
# the otheruser cant rename it from /tmp to output
PHP Warning:  rename(/tmp/test.txt,newName.txt): Permission denied in /home/jmcd/test_rename.php on line 9
wp cli info

OS:     Linux 5.11.0-1028-azure #31~20.04.2-Ubuntu SMP Tue Jan 18 08:46:15 UTC 2022 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php8.0
PHP version:    8.0.15
php.ini used:   /etc/php/8.0/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.28-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/myuser/wp-admin-scripts
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.6.0


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…