title: Cannot upload media via Wordpress uploader
body: <p>This has to do with media uploading in Wordpress.</p>
  
  <p>Every time WP creates a folder for new uploads (it organizes uploads by year and month: yyyy/mm), it creates it with the "apache:apache' user and group, with full access to all (777 or <code>drwxrwxrwx</code>).  </p>
  
  <p>However, after that, WP cannot create a folder within that folder (e.g.: mkdir <code>2011</code> succeeds, but mkdir <code>2011/01</code> fails).  Also, uploads cannot be moved into these newly created folders even though the permissions are 777 (<code>rwxrwxrwx</code>).</p>
  
  <p>Once a month, I have to <code>chown</code> the newly created folders to be the same as user:group as the rest of the files. Once I do that, uploading works fine (which doesn't make sense to me The really frustrating part is that this problem doesn't exist in other WP installs on other domains on the same server.</p>
  
  <p>* I wasn't sure if this should be here or on serverfault.</p>
  
  <hr>
  
  <p>Edit: The containing directory <code>/.../httpdocs/blog/wp-content/uploads</code> has the correct ownership</p>
  
  <pre><code>drwxrwxrwx 5 myuser psaserv 4096 Jun  3 18:38 uploads
  </code></pre>
  
  <p>This is a Plesk/CentOS environment hosted by Media Temple (dv).</p>
  
  <p>I've written the following test script to simulate the problem</p>
  
  <pre><code>&lt;pre&gt;&lt;?php 
  
  $d = "d" . mt_rand(100, 500);
  
  var_dump(
      get_current_user(),
      $d,
      mkdir($d),
      chmod($d, 0777),
      mkdir("$d/$d"),
      chmod("$d/$d", 0777),
      fileowner($d),
      getmyuid()
  );
  </code></pre>
  
  <p>The script always creates the first directory <code>mkdir($d)</code> successfully. On domain A, where the WP problem is, it cannot create the nested directory <code>mkdir("$d/$d")</code>.  However, on domain B, both directories are successfully created.  </p>
  
  <p>I am running each script at <code>/var/www/vhosts/domainA/httpdocs/tmp/t.php</code> and <code>/var/www/vhosts/domainB/httpdocs/tmp/t.php</code> respectively  I checked the permissions on <code>tmp</code>, <code>httpdocs</code>, and <code>domain[AB]</code> and they are the same for each path.  The only thing that differs is the user.</p>