5

Just started using WP-CLI and instead of running with --allow-root, decided to run as www-data user. Things are good so far but cannot install any plugin that way at all:

root@wp-ks320:/var/www/ks320# sudo -u www-data wp plugin install hello-dolly
Installing Hello Dolly (1.6)
Warning: Could not create directory.
Downloading install package from https://downloads.wordpress.org/plugin/hello-dolly.1.6.zip...
Unpacking the package...
#
root@wp-ks320:/var/www/ks320# sudo -u www-data -- wp plugin status hello-dolly
Error: The 'hello-dolly' plugin could not be found.

It's keep saying Could not create directory but creating directory as www-data is not really a problem:

root@wp-ks320:/var/www/ks320# sudo -u www-data -- mkdir wp-content/testDir
root@wp-ks320:/var/www/ks320# ls -l wp-content|grep test
drwxr-xr-x  2 www-data www-data     4096 Nov 15 22:58 testDir

If I use wp --allow-root plugin install hello-dolly instead, it works just fine but created the directory as root for obvious reason. What am I missing here or doing wrong? Best!

2

Based on the issue you've reported and preview of the shell bash, it looks as if you may have the wrong owner/group and permissions set for the website's docroot.

More than likely in your hosting environment, the entire ks320 directory currently does not have www-data as the group assignment.

It can be owned by root but should be assigned to the www-data group (recursively). Running an ls -l from the /var/www directory will output the current permissions, owner, and group assignments to each file and folder.

It probably resembles

drwr-xr-x  ###  root  root  ###   DATE   FILE_OR_FOLDER_NAME

but should resemble:

drwrwxr-x  ###  root  www-data  ###   DATE   FILE_OR_FOLDER_NAME

You can accomplish changing the group assignment from the /var/www directory with the following command:

chown -R root:www-data ks320

Then, you'll also want to make sure the group has read/write/execute permissions on the directory. You can accomplish this from the /var/www directory with:

chmod -R 775 ks320

Once the permissions and group assignments to the folders have been set, your "www-data" user should be able to create the plugin directory and unzip the wordpress plugin files into place.

For more about recommended permissions for a Wordpress site's files and folders, see https://codex.wordpress.org/Changing_File_Permissions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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