Setting File Permissions with chmod on Windows for Apache and PHP

Oftentimes this question comes up for WAMP

How do I chmod 777 (change) filesystem permissions for Apache and PHP to be able to create or write a file/folder on Windows?

The simple answer is you don’t, and you don’t need to. And here is exactly why…

Apache already has all the permissions it needs, as it runs under the LocalSystem account on Windows, which has extensive read/write access to local paths. This is inherited by PHP and the scripts it runs.

For example, when you are using WordPress to upload a file (into the wp-content\uploads\ folder), WP already has ALL the needed permissions it needs to be able to create a new sub-folder (year\month\) in the uploads folder, and to move the uploaded file from the temporary folder into it. No file permission changes are needed. No php.ini edits are needed. No WP settings changes are needed.

If there is a problem then –

  • The additional file permissions that have been set up afterwards are at fault (check Windows Event viewer).
  • The configuration has been incorrectly edited, such as the: WP upload path settings, php.ini temp folder location + upload settings, etc.
  • The Apache Service ‘Log On’ account has been changed from “LocalSystem” to something else (check Service’s Properties).
  • Possibly PHP’s open_basedir setting has been enabled in VirtualHost or .htaccess and is restricting the paths PHP can access.
  • Or there are internal PHP errors (check the website’s HTTP and PHP error logs).

If you do really need to run chmod to set read/write permissions, and chown to set user/group ownership, there are some Windows equivalents and ports of these Linux commands that you can download – that just take the number, re-interpret it, and then apply Windows native methods and commands to set the required permissions:
http://gnuwin32.sourceforge.net/packages/coreutils.htm

But Apache, for the most part, already has *full* read and write permissions in the WAMP folder, so there is nothing that needs changing, unless: you are trying to set lesser permissions, or the script won’t install unless it is able to run chmod/chown.

You can also use a PHP script to run chown/chmod commands, as PHP has its own chmod() and chown() functions:
http://php.net/manual/en/function.chmod.php

Aside from that, to set file-permissions under Windows using native ways, you can right-click any folder or file, go to Properties, Security, and set the permissions there. Or use any number of command-line utilities such as the ones listed here:
http://superuser.com/questions/106181/equivalent-of-chmod-to-change-file-permissions-in-windows

One thought on “Setting File Permissions with chmod on Windows for Apache and PHP”

  1. Thanks for this piece. I have been enlightened to not bother myself on setting permission since its already set.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>