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

7 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?

  3. what I make for this message? Where I must do some correction?
    You don’t have permission to access /p/* on this server.

  4. I’ve found that when Apache is trying to do something, and it complains about permissions I need to go in and add ‘Everyone’ and set those permissions to ‘Full Control’.

    I don’t really feel comfortable with that, and frequently I just do this Everyone and Full Control for a few minutes.

    I’m using Ampps, and there is no way in hell I have space on my C drive for stuff like this. I mean, I know that solid state drives are rapidly going down in price. But.. I’ve bought 50 solid state drives in the past 10 years, and I’m done. I just can’t spend another dime on computer shit.

    I am trying to figure out how to get Ampps to truly run Apache and mySQL as a service.. but for now, I’m probably going to just setup a limited user account for ApacheService and MySql service, and then try to use those Windows accounts to start and stop the services in question.

    I just wish that Fast User Switching was still a practical option. I use Windows Server on almost every machine I touch, and I just cannot remember how to do the Fast User Switching.

    the only thing that makes me nervous.. is that for the past 6-8 weeks. I have had a large number of malware infections. Usually Malware Bytes is my first choice.. but I have to find some AV that is free on Windows Server. I am *VERY* friggin impressed by the new Windows Security with Defender in Windows Server 2019.

    I just don’t trust most security products I see. I used to write antivirus at Microsoft a bunch of years ago, and it’s just not easy to convince me that I should use a new AntiVirus.

    I’m hoping to start using the Sophos UTM product soon. and I hope that can do something for me (and more importantly, I hope that the Sophos Home UTM won’t complain that I’m using Windows Server).

    It sucks that Windows Server is a requirement for almost everything I do. But my first 20 years were spent focused on MS Sql Server, and I just don’t have time for the bullshit involved in translating between Windows Server and Windows Client.

    I just think that this AMPPS setup is going to have to get moved into a VM. Which means.. Next Month. I format relgiously about once a month on most of my machines. I’ve had a LOT of trouble trying to use a thumb drive and copy windows to it using ANY method. I’m always running into messages like ‘Windows 7 USB Tool install has been restricted by (group policy)’. But I almost never use Active Directory.

    Well.. this month, this time.. I’m thinking I’m gonna turn my strategy on it’s head.. and start using a seperate Active Directory on almost every machine I touch. That was what we did at MSN I guess it was 13 years ago. Everything involved Active Directory, and I’m hoping that I can get a lot better at setting up Cross-Domain trusts. Working at MSN doing Active Directory Domain Services on every single Web Server, it was a giant friggin hassle.

    But today, this world. I just need better tools and more configuration options. I do a lot of scripting though.

    but when MOST people talk about scripting, they just run a ton of scripts and it involves a bunch of spaghetti code.. and it’s unmanageable. I always prefer storing LOGIC about the scripting in a RDBMS, and then just using the scripts to run based on what the database says.

    I just don’t think that I’m ever going to break this ‘Database First’ mentality.

Leave a Reply to anafa david mudi Cancel 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>