Apache on Windows: Serving Files From the Network

Recently I had a problem: Without going into the “whys” here, I found myself on a Windows XP system needed to parse and serve PHP files in Apache from a network share. Sounds easy enough, right? Unfortunately, the obvious answer didn’t work, and hours of Googling turned up countless suggestions, most of which didn’t work at all. I even found some very detailed step-by-step instructions that turned out to be based upon a premise that doesn’t work at all.

As it turns out, this is a problem with a very simple, yet unobvious, solution, and today I will share it with you. With any luck, Google will start serving up this post to others looking to serve files in Apache on Windows from a network file share.

My specific goal was to share a project directory on my Linux development system to be run on my Windows XP testing system; for reasons beyond the scope of this post, the Windows XP system is where my Apache server is running. I made my project directory available on the network as an SMB share at \\server\project; I wanted an alias configured to redirect the /p virtual directory to my project directory, which I mapped as a network drive to Y. My first attempt was simple:

Alias /p Y:/project

But Apache just threw a 404 error when attempting to access anything under that directory. Adding a Directory block for that network drive didn’t work either – instead, Apache threw an error when trying to restart.

I spent hours Googling this problem, reasoning that I’m not the only person who needed to do this. I found tons of suggestions ranging from “Map the network drive” (which I just did, with no success) to “Mount the share within your NTFS file system on C” (which, following the step-by-step directions provided by the helpful user, failed to work at all).

Finally, I hit upon the solution: Use the UNC path instead of the network drive letter. Now my Apache config looks like this (abbreviated for clarity):

DocumentRoot "C:/web/htdocs"
<Directory "C:/web/htdocs">
    Options None
Alias /p //server/project
<Directory //server/project>
    Options Indexes

Apache now very happily serves files from this network share without batting an eye. Why this very simple solution was so hard to find is completely mind-boggling. The internet seems to be littered with useless and false information for this problem, so here’s my feeble attempt to provide some quality aid to those who find themselves in the same pickle.

This entry was posted in How-to and tagged , , , . Bookmark the permalink.

18 Responses to Apache on Windows: Serving Files From the Network

  1. lanky says:

    Heh, why didn’t you ask me about this? I had a Windows 2000 box running a few years ago that was sharing data that was on my Linux machine in the exact same method.

    Fun isn’t it?

  2. Kromey says:

    Well, why didn’t you tell me so three weeks ago so I could have benefited from your knowledge and experience? 😛

    Mostly I’m hoping Google will start picking up this post in searches like the ones I did, so that others in my (our) place can find some actual good information that *gasp* works!

  3. But I like pickles! I’ll help your Google placement:

    apache, smb, network share, map, Y drive, no wait (not Y drive), //server, no (too cryptic…)

    Oh well, perhaps your post will suffice.

  4. Scasquiov says:

    Couldn’t make it to work unfortunately… What user are you running apache as? have you given that user any special permissions on the machine serving the files over smb?


    • Kromey says:

      Apache is running as the user Apache. I just noticed that I had the user in both the Administrator and User groups still, which were earlier (misguided) attempts to get it to work.

      My SMB share is coming from a Linux host, and has full read/write permissions to all (i.e. no user-level security). This is viable in my environment because the SMB share is in fact a shared directory from the VM’s host (my Windows machine is a VM running in Virtual Box on a Linux host); if this isn’t viable for you, you might try a read-only “open to everyone” share, or else grant your Apache user access to your SMB share, although I don’t know what kind of support there is for password authentication using this method.

  5. Edward Savage says:

    I am trying to set the DocumentRoot to a UNC path, and I get the error: DocumentRoot must be a directory

    Any suggestions there? I’ve been Googling, and finding posts with people having the same error, but no solutions.

    • Kromey says:

      A couple of things you can try:
      Try the DocumentRoot’s UNC path both with and without the trailing slash.
      Make sure you’re using forward slashes (/) and not Windows-style backslashes (\) – I couldn’t get the UNC path to work at all with backslashes.
      Make sure you’re using a directory and not the root of the share – i.e. use //servername/folder and not //servername, as the latter will not work.

      If none of the above tips get you there (I’ve never tried to set the DocumentRoot to a UNC path), set your DocumentRoot to a local path instead and then configure an alias for your root directory like so:
      Alias / //servername/folder
      I know an Alias can point to a UNC path – that’s what I set up in this article – so this might be your only option.

  6. Windragon says:

    I want thanks you for this, I looked for a working and easy to understand tip for weeks.
    I want add my cent:

    With the source you’ve put to access to the network drive you need to point at this url: “http://localhost/p/”

    Supposing that like me, you need to completelly override the local documentroot with the network folder content you must:

    Uncomment the line: “LoadModule setenvif_module modules/mod_setenvif.so” (without quotes)

    Then add in the end of the httpd.conf file
    RewriteEngine on
    RewriteRule ^/$ /p [R]

    Where “/p” is the alias name of the network folder

    Writing “http://localhost/p” or “http://localhost” the results will be the sames

    Thanks again

  7. All I can say is:


    I’ve spent more than once looking for this answer and it’s seems pretty damned obvious to me right now that Apache would understand a UNC path. Why it doesn’t understand a mapped drive makes no sense to me though.

    You would think that (excuse the DOS stuff) but Assign, Subst, Map, et. al. would be happening at a lower level that Apache wouldn’t care about. Maybe an Apache programmer/expert will come out of the woodwork and explain why Apache appears to differentiate between a “real” drive and a mapped network drive.

    I just wrote out the above and I should have read the comments, specifically Kromey’s.


    The “dude” stands though.

    • Kromey says:

      Indeed, it’s obvious in hindsight, but just not something that I — nor most everyone else on the internet it seems — had thought of before.

  8. mr.b says:

    Here’s what Apache docs have to say about using network resources:


    Basically, it’s the same thing as you have come up with, but it also provides the answer as to why it doesn’t work the way you’d expect it to work (by simply using mapped drive, for instance).


  9. Tanoshimi says:

    I’ve been trying to do this for ages too! Fortunately, I figured out (rather tried) using UNC, but I get the error Access Denied. I’m fairly sure I understand the problem. The drive I’m trying to access has to be accessed by username and password. I know I had to put it in when I mapped the drive. I was hoping the user would be able to access it, but I guess that’s not so.

    What should I do? I’d like to keep this drive under username and password lock, but I’d also like to Alias it as Alias /music/ \\SHARED\shared\AUDIO\Music.

    (It’d be so much easier if we could just access it via mapped drive letters)

  10. David Patterson says:

    Unfortunately, the link to the Apache docs is broken (404) now.
    I believe that the reason a mapped drive fails is because drives are mapped for the user’s process tree, not for the entire system. This means that only the logged in user has access to the mapped drive. None of the services do.

    Again, obvious once you know what’s happening.
    Thanks for the post. It worked for me and led to me figuring out the rest.


  11. André Pasold says:

    The Apache User question
    I try many suggestions, and after search and test a lot, I find the real problem – cited in the comments above: the user that Apache uses to access the files on the server.

    If you already try all, don’t give up. Here some test that worth to try:

    1. detect which user your apache is using. To do this, create a PHP script with the following script:

    2. if the user shown is different from which you use to access the server, you have to change it. To do this (in windows):
    – go to control panel
    – look for “local services”
    – localize the apache service running (wampapache, in my case)
    – stop the service, open the properties (right click in it) and insert the user and password in the form
    – start the apache and test

    Well, it works in my case. 😉

  12. forMagento says:

    My appache is not starting after the below code updated on httpd.conf

    Options None

    Alias /attach //

    Options Indexes

    • Kromey says:

      You need to have a <Directory> //</Directory> section in your httpd.conf; that’s where you want those Options directives (though they may work in the global scope, I’m not certain on that). Without the Directory section though your Apache won’t know what to do with an Alias that, as far as it’s aware, is pointing to nothingness.

  13. i have tried using this Blog to make my Apache Document root point to a network Folder
    and has also tried using google to get an anwer all was to no avail

    I have a system on the network call “dell-pc” which i want my apache server to point to
    i shared a folder called “new” on the dell-pc which i can access from my system by hitting “\\dell-pc\new”

    The problem is on trying to make my apache server point to the “new” folder on the dell-pc network is now the problem

    Below are my configurations setting for httpd.conf

    DocumentRoot “//dell-pc/”

    Alias “/new //dell-pc/”

    so what am i not doing right here ?

    • Kromey says:

      If you want to point to \\dell-pc\new, you have to put “//dell-pc/new” in your DocumentRoot and Alias directives, not merely “//dell-pc”. Also, Windows gets… weird… when you point anything toward a server rather than a share on said server, so even if you wanted to point to \\dell-pc rather than the “new” share, you probably wouldn’t be able to anyway.

Comments are closed.