Apache can’t write to that directory: fixed

Date: 04 Mar, 2014
Posted by: admin
In: hints & tips|internet, web design & development|linux, open source & software

Bookmark and Share

Access controls mean my website runs as a user that can’t create a directory that is writable by the server; here’s how I fixed it with reference to Updraftplus plugin for WordPress. This fix should work generally.

Apache can’t do that

(“I’m sorry Dave!”)

When apache can’t write to your folders it can often be a permission problem. Usually that means setting the folder to be world-writable – which if you’re like me will make you justifiably nervous, as if you left your car unlocked and your wallet on the seat. In this case – setting up the Updraftplus plugin for WordPress I couldn’t create a directory that the plugin could create files for. See all controls I have direct access to make folders/dir that are owned by my username and group. Apache is running under the username apache in the apache group (pretty normal). Here’s how I worked around it fixing this issue …

PHP script and permissions

A little PHP jigger-pokery means that I can temporarily allow the server, as user:apache, to create a directory. Then one can rescind permissions leaving a directory that the server can still write to:

  1. First I set the parent dir, wp-content in this case, to mode 0777 to make it writable by user “apache”.
  2. Now make script in the directory where you wish to have the new directory (accessible by the server); “updraft” is the to-be-created folder’s name:
    // mkdir.php
    <?php mkdir(“updraft”, 0750); ?>
  3. Access the above script in your browser.
  4. Test that your script, plugin or website is working as required and can access the new directory. The user:group are apache:apache for me here whereas FTP or direct access to the webserver control panel (Parallels or cPanel or whatever) will only make folders as myuser:mygroup.
  5. Reset permissions on the parent folder, wp-content reset back to 0755 in this case.
  6. Remove mkdir.php script.

Updraftplus permissions problem fixed

There we have it. In my specific case the server running as user apache was still able to access the folder created (with owner and group “apache”). If this works for you too, let us know in the comments.

Sorry, comments are closed.


About

Flapjacktastic is just a random collection of musings, hints&tips, notes, information ... a collection of stuff really that's overflowed from the brain of this husband, father, potter, business-man, geek ...

past posts