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:

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:

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:

2 thoughts 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.

  2. Hi, I ran into a problem with permissions when i wrote a delete method to, not only delete a photo record in the database but to, delete the photo from the image directory. Is my situation a peculiar one?

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>