title: PHP - Apache can't write in a directory that just created
body: <p>I have a scripts that allows to assign files to products.  To avoid problems with name files repeating, each product has a specific directory.</p>
  
  <p>The uplad directoy that contains all product-specific directories looks like this.</p>
  
  <p>4 drwxrwx--x  3 pepe pepe  4096 Jan  9 17:08 . <br/>
  20 drwxrwxr-x 35 pepe pepe 20480 Jan  9 15:42 ..<br/>
   4 drwxrwxr-x  2 apache  apache   4096 Jan  9 17:08 001</p>
  
  <p>Apache runs under user "apache" and "apache" is set as part of group "pepe".</p>
  
  <p>If I try to upload a file to a product that doesn't have it's directory created the scripts create the directory (with the permissions shown for dir "001") and then tries to upload the file, but fails.</p>
  
  <p>If I change the directory owner to pepe.pepe in SSH and then reupload the file it goes perfectly.</p>
  
  <p>Why is apache creating a directory that in the next line of code can't write in?</p>
  
  <p>How do I prevent to have to manually change ownership to the directory created, because my client obviously can't do it when assigning the files to all his products.</p>