I've configured private file system. Using it from UI works well. I want to generate dump site content via devel_generate with custom modifications. So I'm hooking into Node API for assigning sample PDF files to nodes.

Inside private directory I want to create directory structure:

  $dir = sprintf('private://org%d/%d/person%d', $this->getOrganization()->nid,
                    date('Y'), $this->getEmployee()->uid);

  if (!file_prepare_directory($dir)) {
    throw new Exception('Cannot create document file directory or it\'s not writable');

But exception is thrown.

How to set proper directory permissions? Content is generated via drush command - drush genc.

  • You need to run Drush under the same user your web server runs, or give Drush write permissions over the private file system
    – Clive
    Commented Nov 26, 2015 at 13:17
  • Thanks, I'm trying things like: sudo -uwww-data /usr/bin/drush cc all but getting drush command not found
    – Codium
    Commented Nov 26, 2015 at 13:59
  • I've same error when creating nodes via UI also...
    – Codium
    Commented Nov 26, 2015 at 14:44
  • Sorry, would need access to your server to be able to debug, can't do it from here
    – Clive
    Commented Nov 26, 2015 at 14:45

1 Answer 1


Ok, I solved it by passing proper flag (for UI):

file_prepare_directory($dir, FILE_CREATE_DIRECTORY);

For using drush command still don't know and failing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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