Virtual Host: LAN access, WAMP, Windows 7, Apache 2.4.4, Php 5.4.16; returns dont-have-permission-to-access-on-this-server

StackOverflow https://stackoverflow.com/questions/22882997

  •  28-06-2023
  •  | 
  •  

سؤال

Before I start.. Good day to all! :)

I have problem with my WAMP virtual host.. the other computer on our LAN keeps receiving error forbidden-you-dont-have-permission-to-access-on-this-server..

Below is the current settings I have:

/httpd.conf

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    Options FollowSymLinks Includes
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order Deny,Allow
    Allow from all
    Allow from 127.0.0.1
    Allow from ::1
    Allow from localhost
</Directory>

/phpmyadmin.conf Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.0.4/"

# to give access to phpmyadmin from outside 
# replace the lines
#
#      Order Deny,Allow
#   Deny from all
#   Allow from 127.0.0.1
#
# by
#
#        Order Allow,Deny 
#   Allow from all
#

<Directory "c:/wamp/apps/phpmyadmin4.0.4/">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride all
    Order Deny,Allow
    Allow from all
    Allow from 127.0.0.1
    Allow from ::1
    Allow from localhost
</Directory>

/httpd.vhosts.conf

Listen 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
    ServerName www.ecommerce.local
    ServerAlias ecommerce.local
    DocumentRoot C:/wamp/www/ecommerce
    ErrorLog "C:/wamp/www/ecommerce/logs/error.log"
    CustomLog "C:/wamp/www/ecommerce/logs/access.log" common
    <Directory />
        Require all granted
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerName localhost
    DocumentRoot C:/wamp/www/
</VirtualHost>

Also...

  • tried to ping from other computer response is success
  • tried to turn off firewall for both computer
  • tried to add everyone in www's folder properties changed_to_everyone

I have tried other solutions I found but still to no avail.. I can access "http://ecommerce.local" but the other computer on our LAN recieves forbidden-you-dont-have-permission-to-access-on-this-server error..

does it have something to do with our network settings? the other computer is also in the same settings... my ip: 192.168.1.198 and the other computer is 192.168.1.192 ipv4 and ipv6 settings

هل كانت مفيدة؟

المحلول

Access to Apache has nothing to do with windows access rights on a Windows system. Its all to do with what you tell Apache to allow in.

Also you are using a mixture of Apache 2.2 and Apache 2.4 syntax in most of your access declarations.

Apache 2.2
Allow .....

Apache 2.4
Require .....
Require local - means 127.0.0.1 and localhost and ::1
Require ip    - specifies a single ip (192.168.0.10) or a range of ip's (192.168.0)

Apache does not seem to complain yet, but its probably best to stick to the Apache 2.4 syntax.

This first change you made is very dangerous and should be changed to this unless you really wanted to give unlimited access to the servers C:\ drive to anyone that hacks your Apache server.

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    Options FollowSymLinks Includes
    AllowOverride All
    Require all denied

</Directory>

Again here use Apache 2.4 syntax and be specific about who you want to allow in.

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/wamp/www"
<Directory "c:/wamp/www">
    Options Indexes FollowSymLinks
    AllowOverride All

    Require local
    Require ip 192.168.0

</Directory>

Now to your Virtual Host definitions

You dont need this Listen 127.0.0.1:80

Put the localhost definition first so it becomes the default domain, so if a random or misspelt domain name is used this will load. If that comes from an internet ip then they will get an error as only ip's from within you network are allowed access. This isreally for later when you decide to open up your site to a wider audience.

Also dont specify 127.0.0.1 on the line, you want it to be listen any incoming ip not just this machine.

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/wamp/www"
    <Directory "c:/wamp/www">
        Options Indexes FollowSymLinks
        AllowOverride All

        Require local
        ## May not want to let people access the wamp page so leave this off if not.
        Require ip 192.168.0

    </Directory>
</VirtualHost>


<VirtualHost *:80>
    ServerName www.ecommerce.local
    ServerAlias ecommerce.local
    DocumentRoot "C:/wamp/www/ecommerce"

    ## not a good idea to have logs visible under the DocumentRoot folder
    ## should really go in C:\wamp\logs
    ## But I assume you want developers to have easy access during development
    ## ErrorLog "C:/wamp/logs/ecommerce_error.log"
    ## CustomLog "C:/wamp/logs/ecommerce_access.log" common

    ErrorLog "C:/wamp/www/ecommerce/logs/error.log"
    CustomLog "C:/wamp/www/ecommerce/logs/access.log" common

    <Directory />
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All

        Require local
        Require ip 192.168.0

    </Directory>
</VirtualHost>

Now you may want to allow your local developers access to phpMyAdmin. If so you will need to change your C:\wamp\alias\phpmyadmin.conf file as well.

<Directory "c:/wamp/apps/phpmyadmin4.0.4/">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride all
    Require local
    Require ip 192.168.0
</Directory>

Or you could be more specific here and only allow certain ip's to use phpMyAdmin by using something like this

Require ip 192.168.0.10 192.168.0.11 192.168.0.12

Just as a side note. I personally like to move my VistualHosts sites completely out of the C:\wamp\ folder structure. So I would have placed my ecommerce folder somewhere like C:\websites\ecommerce\www\. This keeps any confusion about access rights to a complete minimum and also if I need to upgrade WAMP, my website code is never in any danger when I make a silly typo.

ADDITIONAL INFO:

Now to be able to access your new site as ecommerce.local or www.ecommerce.local you will have to make a chnage to your HOSTS file.

C:\windows\system32\drivers\etc\hosts

On the PC running WAMP add this line:

127.0.0.1 ecommerce.local

On the other PC's do this

192.168.0.10 ecommerce.local

Where 192.168.0.10 is the ip address of the PC running WAMP

Then reboot the PC's or do these 2 commands from a command window started as Administrator

net stop "DNS Client"

net start "DNS Client"

نصائح أخرى

I have already solved my own issue... I have not shared my folder for anyone to view... so what I did is:

  1. Right Click the project folder
  2. On folder options go to sharing tab
  3. Click on advance sharing
  4. advance sharing option will open then tick share this folder
  5. click permissions
  6. permissions option will open then choose whom you would like to share your folder
  7. I chose everyone then below tick full control (*for trial purposes only; recommended tick only Read)
  8. then click ok for all the opened options

how to share folder

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top