Search code examples
apachewindows-server

Trouble configuring Apache to make web application be able to access folder outside DocumentRoot


So after searching around here I found how to do what I want, but I have two environments, in one it works and in the other it doesn't and I can't figure out why.

Let's call the working environment A and the one where it doesn't work B.

In A, the folder I want to access is in A itself (the server hosting Apache), just on a different folder structure outside of the DocumentRoot. So I have the following in my httpd.conf file:

Alias /folder/ "C:/folder/"

<Directory "C:/folder/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all 
</Directory>

To make sure that it worked in A, I had a PHP script that generated a text file and saved it inside that folder. It worked without problem.

In B, the folder I want to access is in another server (A), that folder is mapped in B as "P:" unit (I can see and access it through explorer without any problem). I have the following in the httpd.conf file:

Alias /folder/ "P:/"

<Directory "P:/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all 
</Directory>

When I try to restart the apache service in B with the above block in my httpd.conf I get an error message (Windows could not start the Apache2.4 on Local Computer...) but no error message in Apache's error.log file. When i remove that block i can restart it without a problem.

Thanks in advance and sorry if I wasn't clear enough but english isn't my native language.

EDIT: apparently you cant use mapped units on the httpd.conf file. I tried to use the full address like below and now Apache can restart without error but I can't generate my .txt file via PHP script in the desired folder.

Alias /folder/ "\\10.76.4.60/folder/"

<Directory "\\10.76.4.60/folder/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Solution

  • Problem was solved by setting the Apache process to be started using a specific user that could access the mapped folder. By default the process is started with the user "SYSTEM". Since the server was running on Windows this could be done through the administrative tool Services (mmc.exe).

    After doing this and resetting Apache I was able to do what I needed which was saving a file in the desired mapped folder through some script running in the webserver.

    Also there was no need to put ANYTHING in the httpd.conf file.