4

I've been searching for a few days now trying to figure out a solution to this problem, but I've given up and its time to ask for some help.

I'm running Wordpress on an Ubuntu 14.04 x64, using a Vagrant server created with PuPHPet (an automated GUI for creating boxes with Vagrant, Puppet, and Hiera for those who are unaware). I use Mark Jaquith's WP-Skeleton Wordpress folder set up, and have two shared folders set up; /var/www/wp (sitename/www/wp on the host) for Wordpress core files, and /var/www/content/ (sitename/www/content on the host) for a custom content directory which is the purpose of WP-Skeleton.

When SSH'ing into the VM and running WP-CLI, everything seems to work correctly as far as WP-CLI knowing the Path to my Content directory, and Wordpress core files. The problem is when trying to install plugins or themes, as shown below-

[07:20 PM]-[vagrant@packer-virtualbox-iso-1422601639]-[/var/www]-[git master] $ wp plugin install jetpack Installing Jetpack by WordPress.com (3.3.2) Downloading install package from https://downloads.wordpress.org/plugin/jetpack.3.3.2.zip... Unpacking the package... Warning: Could not create directory.

My first, and only thought so far is that this is a permissions error, but with my limited knowledge of this area, I've only been able to do so much, however, I can say that I've tried changing the permissions of the Content directory to 755, then 765, and even 777 using chmod -v 755 /var/www/content/.

That also didn't work, even with the permissions set to 777. So what else could be wrong? I know this probably has to do with permissions for www-data, but like I said, I have limited knowledge of what to look for, or change. I'm sure this is something simple, and I'm sure this isn't directly related to WP-CLI, as I have a feeling if I used any other web app to try and install to the www folder that I'd have the same problem.

If anyone needs any information from me, I'll include it such as my congif.yaml file (which when using Hiera with Puppet stores all of the info that would normally would be in the Vagranfile, and automates installing Puppet modules). It also includes info about the Ubuntu box, folder set up, etc.

Thanks in advance, P.J.

Update:

I would like to add that adding sudo wp plugin install jetpack --allow-root will work when I use WP-CLI, however, I shouldn't have to use sudo if I'm the root user, should I?

P.J.
  • 295
  • 3
  • 13

3 Answers3

5

I found an answer here to make it work on my local MBP OSX Server. Add define('FS_METHOD','direct'); to wp-config.php.

Make sure all files and folders are 775 (did not reduce the permissions yet but I am positive less is workable - i.e. 664 for files - locally too) and all files and folders are owned by your user and group _www. Inside the project folder run:

sudo chown user:_www  *
sudo chmod -R 775 *

This should allow you to run wpcli and create directories without issues and without using root.

NB _www is for OSX Apache user group. For Ubuntu you need www-data

NBB Running Mod PHP here, with (Fast) CGI (Shared) Hosting setup 755 for directories and 644 for files normally works well.

rhand
  • 1,176
  • 4
  • 17
  • 45
  • This works, and a long with the answer below should solve anyones problems. I was also making the mistake of putting me project files directly in var/www instead of var/www/mysitename. Thank you guys. – P.J. Mar 17 '15 at 03:03
  • I prefer to chmod only the directories -- that should work, right? The command I use is `find /var/www/html -type d -exec chmod 775 {} ";"`. – Keith Bennett Jul 08 '16 at 07:45
  • 1
    To answer my own question, chmod'ing only the directories was not enough. When I ran `wp core update`, I got an error message that there was a permission error regarding '/var/www/html/wp-admin/includes/update-core.php`. This was fixed when I executed the suggested `chown -R` command. – Keith Bennett Jul 08 '16 at 07:51
  • Permissions give me so much rage! `sudo chown user:www-data` and `sudo find /var/www/html -type d -exec chmod 775 {} ";"` *finally* get wp-cli to install things as well as the site does not require FTP creds to install/uninstall plugins. I've read to avoid `FS_Direct` on live servers, but I'm still concerned that these permissions are too permissive. I keep reading about "hardening" but then nothing (like wp-cli or dashboard update) don't work. – helgatheviking Aug 08 '16 at 15:49
1

Maybe you have to define in your config.php file where is located the content directory. Depending on configuration of your server, try adding one of this two line of code:

define('WP_CONTENT_DIR', realpath(dirname(__FILE__) . '/content'));

or

define('WP_CONTENT_DIR', realpath($_SERVER['DOCUMENT_ROOT'] . '/content'));

Try with the first, if it doesn't work try with the second. I've found the same error configuring wp-deploy and this worked for me.

  • Thank you for the reply, I'm glad someone has seen something similar. I'll try it out! – P.J. Mar 12 '15 at 18:29
  • I actually just realized those paths are already set in my config file. I will say this, if anyone else see's this, that might be a place to start. Thanks for the answer. I'm going to try the suggestion for – P.J. Mar 17 '15 at 00:53
  • *from rhand, and another on a different board now that I have some time. Thanks guys. – P.J. Mar 17 '15 at 00:54
0

For me, all I had to do was sudo chmod -R 775 wp-content. The owner did not affect the plugin update for me and I did not have to make any other changes.

Regarding what @helgatheviking was saying about "hardening"... If you're worried about security and want to be secure as possible change it back to 755 afterwards! I'd say that this is a good thing to do as long as you don't mind changing the permissions with every WP-CLI plugin update.

sdexp
  • 756
  • 4
  • 18
  • 36