Unable to access directory outside Virtual Host
Posted by: pbhcpa (---.static.grandenetworks.net)
Date: March 02, 2020 08:21PM

Hello!

We're using WAMP to serve up a compliance website that we are working on. Basically the structure is this:

\wamp64\www\compliance
-index.php

\wamp64\www\includes
-compliance_style.css
-compliance-sidebar.php
-dbh.inc.php


Inside the index.php, we call the compliance-sidebar.php, which does not load and the compliance_style.css file is not processed.


Here is our http-vhosts:

# Virtual Hosts
#
<VirtualHost *:80>
ServerName compliance
DocumentRoot "c:/wamp64/www/compliance"
</VirtualHost>
<Directory "c:/wamp64/www/compliance/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>

#
<VirtualHost *:80>
ServerName includes
DocumentRoot "c:/wamp64/www/includes"
</VirtualHost>
<Directory "c:/wamp64/www/includes/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>

#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
</VirtualHost>
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow From 192.168.0
Allow from 10.10.40
</Directory>

Any thoughts on what I might be doing wrong?

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: pbhcpa (---.static.grandenetworks.net)
Date: March 02, 2020 11:54PM

We figured it out, using Alias.

[stackoverflow.com]

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: Otomatic (Moderator)
Date: March 03, 2020 09:43AM

Hi,

Creating a VirtualHost for the includes of another VirtualHost is not a good solution.

Also, the VirtualHost localhost must stay in first position and keep Require local; your Allow From is for Apache 2.2.

------------------------------------------------------------------------------------------------------------
Wampserver 3.2.0 32 bit - Apache 2.4.43 - PHP 7.4.4/7.3.16/..../5.6.40 - MySQL 5.7.29 - MariaDB 10.4.12
Wampserver 3.2.0 64 bit - Apache 2.4.43 - PHP 7.4.4/7.3.16/..../5.6.40 - MySQL 5.7.29/8.0.19 - MariaDB 10.4.12
PhPMyadmin 5.0.2 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: pbhcpa (---.static.grandenetworks.net)
Date: March 03, 2020 03:37PM

Thank you for your response. I misunderstood the wording on the localhost page "These are your folders in c:/wamp64/www. To use them as an http link, you must declare them as VirtualHost". We're not making a web link, just a filesystem link. I've removed that virtual host and the alias and we can link just fine to the other directories outside the root.

If I change the order of the Virtual hosts as you recommend, then we cannot access any of the other websites, even with "Require all granted". What are we missing?

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: pbhcpa (---.static.grandenetworks.net)
Date: March 03, 2020 04:29PM

Here is the updated httpd-vhosts.conf file:

# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot "${INSTALL_DIR}/www"
</VirtualHost>
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride None
Require local
</Directory>

#
<VirtualHost *:80>
ServerName compliance.domain.com
DocumentRoot "c:/wamp64/www/compliance"
</VirtualHost>
<Directory "c:/wamp64/www/compliance/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride None
Require ip 192.168.0
Require ip 10.10.40
Require host domain.com
</Directory>

We can again access the website locally (thanks), but I'm back to the original issue of unable to call a file from outside the root web directory.

We have the .css file stored in the same folder called includes with the database connection string file. We can call the db string file but not the .css file. This is the statement being used:

<link rel="stylesheet" type="text/css" href="../includes/compliance_style.css" />

Any suggestion?

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: pbhcpa (---.static.grandenetworks.net)
Date: March 03, 2020 04:34PM

Please disregard, I finally found an article stating that you can't have .css outside the root. Thank you for your help.

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: Otomatic (Moderator)
Date: March 03, 2020 04:43PM

Hi,

The question to ask is why would it be mandatory to create a specific VirtualHost to put the files needed for another VirtualHost.
Why is it not possible to put your includes in a VirtualHost compliance folder, for example in c:/wamp64/www/compliance/includes/?

As it is well explained in the Apache documentation, the way to cleanly and securely access a folder outside the VirtualHost tree is to use aliases, this is what is done for PhpMyAdmin and Admin access under Wampserver.

At the hosts, it is not possible, and is even totally forbidden, to have access to the "filesystem" and fortunately for the flatmates.

Putting the VirtualHost localhost in first position and with Require local puts it in VirtualHost by default which will make any http request that can't be served will fall on the default VirtualHost without being able to access the filesystem since it is totally forbidden in httpd.conf for the default VirtualHost nammed localhost.

------------------------------------------------------------------------------------------------------------
Wampserver 3.2.0 32 bit - Apache 2.4.43 - PHP 7.4.4/7.3.16/..../5.6.40 - MySQL 5.7.29 - MariaDB 10.4.12
Wampserver 3.2.0 64 bit - Apache 2.4.43 - PHP 7.4.4/7.3.16/..../5.6.40 - MySQL 5.7.29/8.0.19 - MariaDB 10.4.12
PhPMyadmin 5.0.2 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: Otomatic (Moderator)
Date: March 03, 2020 04:47PM

Hi,

> you can't have .css outside the root.
It depends on what exactly is meant by "root"!

For my sites, assuming the root folder is mysite,
css are in mysite/css/
the includes are in mysite/inc/
js scripts are in mysite/js/
and the like

------------------------------------------------------------------------------------------------------------
Wampserver 3.2.0 32 bit - Apache 2.4.43 - PHP 7.4.4/7.3.16/..../5.6.40 - MySQL 5.7.29 - MariaDB 10.4.12
Wampserver 3.2.0 64 bit - Apache 2.4.43 - PHP 7.4.4/7.3.16/..../5.6.40 - MySQL 5.7.29/8.0.19 - MariaDB 10.4.12
PhPMyadmin 5.0.2 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote
Re: Unable to access directory outside Virtual Host
Posted by: pbhcpa (---.static.grandenetworks.net)
Date: March 03, 2020 05:18PM

Root = default web site directory.

That is what we ended up doing: css in compliance/css

Options: ReplyQuote


Sorry, only registered users may post in this forum.