Friday, November 1, 2013

WampServer and Apache httpd.conf: ServerName, DocumentRoot, Directory and Alias




1) PREPARATION
2) SETUP
3) EDIT HTTPD.CONF

WampServer is a software suite that contains Apache, PHP and MySQL servers.
Apache server configuration is stored in a file called httpd.conf.
Amongst all, httpd.conf defines ServerName, DocumentRoot and Directory. These three items specify the physical location of any particular website, its name and its network access types.

1) PREPARATION

1.1) There are many kinds of Apache-MySQL-PHP suites and each suite may have different way of managing httpd.conf. For the purpose of this tutorial, we will be using WampServer version 2.0i.
1.5) Optionally, you may need 7-zip portable in case you need to zip/unzip files later on. (Direct link to 7-zip portable:

2) SETUP

3) EDIT HTTPD.CONF

3.1) Open the file. It is located in the {wamp home}\bin\apache\Apache2.2.11\conf.
3.2) By the default the ServerName, DocumentRoot, Directory are located at the following lines:
171. ServerName
178. DocumentRoot
205 - 236. Directory
3.2) Let’s say we want to change the DocumentRoot c:/wamp/www/mysite1/
3.2.1) Create the subfolder mysite1 under www folder.
3.2.2) Create a file index.php inside mysite1 folder and type the following codes into it:
<?php
echo “<h1>MySite1</h1”;
?>
3.2.3) Edit httpd.conf as follows:
Line no. 178: DocumentRoot “c:/wamp/www/mysite1/”
Line no. 205: <Directory “c:/wamp/www/mysite1/”>
3.2.4) Restart Apache.
Click Control Panel/Apache/Service/Restart Service.
3.2.5) Outcome:
3.3.) Let’s say we want to use a domain name mysite1.local instead of localhost.
3.3.1) If you type the URL http://mysite1.local now, you will get:
The computer doesn’t recognize the address. If your computer is connected to the Internet, probably you will be forwarded to a search engine instead.
3.3.2) We need to tell the computer the ip for mysite1.local, e.g. 127.0.0.1. Using notepad++, open the file c:\windows\system32\drivers\etc\hosts:
3.3.3) Go to the right of the localhost, type a space and type “mysite1.local” (without the quotes).
3.3.4) Save the file.
3.3.5) In httpd.conf file, replace the localhost with mysite1 at line no.171 as follows:
3.3.6) Restart your PC (for step 3.3.3 to take effect).
3.3.7) Go to URL http://mysite1.local/ 
3.4) An Alias is used to provide the alternative location for a directory under a domain.
3.4.1)  For e.g., if you browse URL http://mysite1.local/phpmyadmin/ you will get the following:
3.4.2) Recall Step 3.2.1, the physical location mysite1 doesn’t contain phpmyadmin directory. So, where is the folder stored actually?
3.4.3) There is an entry in httpd.conf that includes a call to another configuration file located in “c:/wamp/alias/”
3.4.3) Go to the folder, you will see the file phpmyadmin.conf
3.4.4) Open the file and you will see the physical location of phpmyadmin. It was stored in c:/wamp/apps/phpmyadmin3.2.0.1/
3.4.5) By using an alias, a directory can be stored outside of a website directory and can be shared by many domains, e.g. mysite1/phpmyadmin, mysite2/phpmyadmin etc.

No comments:

Post a Comment

Labels