In the past few days, I have developed an internal tools with PHP and MySQL. To let my colleagues access my tool, I am setting up an Apache server on my Windowns 7. I just download and install the WampServer on my Windows PC. To allow other computers to access my web server, I have to make some small configuration on my Apache server.

Change Listen IP Address

To enable other computers to access your Apache server on Windows, we need to change the listen IP address in the httpd.conf first. By default, the Apache server will listen the local IP address:

Listen localhost

or

Listen 127.0.0.1:80

For example, if our IP address is 192.168.0.120, we can change the config as following:

Listen 192.168.0.120:80

Config DocumentRoot

Usually, we don’t change the default value of this opiton. In WampServer, the default value is:

DocumentRoot "D:/Program Files/wamp/www"

If you website content is hosted in different folder, you can change this value.

Set Folder/Directory Access Permission

Here, I will show you some simple cases to demonstrate the access control configuration in Apache. Usually, we only put the website content in the document root folder. But sometimes, we may put different applications in different folders in the document root folder. If we only want users to access a certain folder and restrict to access other folders in document root folder, then we can configure access permission for different directory.

First, we will restrict the document root folder access right. This is the default configuration in Apache. Then, we just keep it without any changes.

<Directory />
    AllowOverride none
    Require all granted
    Order Deny,Allow
    Deny from All
</Directory>

Second, we need to overwrite the access right for the sub folders in the document root folder. For example, we have two sub folders in the document root folder: public_web and private_web. We will allow other users to access public_web folder, but only allow local computer whose IP is 192.168.0.120 to access private_web folder. Then we need to set up the Directory configuration as following example:

<Directory "d:/wamp/www/public_web/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Allow from all
</Directory>

<Directory "d:/wamp/www/private_web">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order Deny,Allow
    Deny from All
    Allow from 192.168.0.120
</Directory>

Then, people can use following url to access your content in public_web folder.

http://192.168.0.120/public_web

Do you think this url is too long to type? There is way to change the above URL to a shorter form, for example:

http://192.168.0.120/p

This requests us to enable the alias_module in Apache. And it is enabled by default. What we need to do is to assign a alias to public_web. Find the and update as following configuration:

<IfModule alias_module>
    Alias /p "d:/wamp/www/public_web/"
    ScriptAlias /cgi-bin/ "D:/Program Files/wamp/cgi-bin/"
</IfModule>
Previous PostNext Post

Leave a Reply

Your email address will not be published. Required fields are marked *