I sometimes get dragged into the world of Application Servers and I spent several hours trying to sort this today on a Windows machine – I prefer Linux but we have some folks here who still insist on using Windows for web servers and such like.

Anyway, the requirement was to share a drive from the database server (also windows! *shudder*), access this from another windows server running apache, and ultimately make this available as a directory listing via a web browser, like so:-

index of files

Simple enough you’d think.

Well here’s what I did first time round (or how NOT to do it)

I shared a folder from the database server¬† (let’s call it “util”).

Ensure that you can access the share from your web server box – either map the drive or navigate via the UNC path.

Next,

Add an alias (let’s call it “apps”) to your httpd.conf file in the Alias section:

Alias /apps/ "//servername to map from/util/apps/"

Then I added a directory entry as follows:

<Directory "apps">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>

I restarted apache..

Went to a browser (http://servername/apps/) and got a “Forbidden You don’t have permission to access /apps/ on this server :-

screenshot.5

However, if you specifiy a file that’s actually in this folder you can download it!

What we want though is a directory listing of ALL files.

>> cue several hours of googling and changing alias and Directory directives and restarting Apache again and again and again

The Solution

The key point here is that the Directory entry for “apps”, above, isn’t for the alias we created. It’s actually for another directory, called apps, but relative to the htdocs/DocumentRoot directory.¬† So if you have a default DocumentRoot of .. Apache/Apache/htdocs then this directive applies to Apache/Apache/htdocs/apps whether it exists or not.

In order to give permissions to the aliased apps directory you need to explicitly reference the UNC path of the shared folder like so:

<Directory "//server to map from/util/apps/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from All
</Directory>

Restart Apache…

Now you should be able to get a directory¬† listing…you can remove the “apps” directory directive too.

So to summarise,

1) No need to map the folder – just share it and use the full UNC to reference it.

2) Create an alias using the UNC in httpd.conf similar to:

Alias /apps/ "//servername to map from/util/apps/"

3) Create a directory entry explicitly to the UNC path similar to:

<Directory "//server to map from/util/apps/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from All
</Directory>

4) Restart apache and browse to http://yourapacheserver/apps/ to see a list of files!

index of files

That’s it!

</dbaninja>

About these ads