Configuring Document Root and Virtual Hosts

If you're unhappy with the default document root (the place where your Web server files are located), you can change it by modifying Apache's configuration file. To do so, you typically have to locate httpd.conf, as it is the main configuration file. Use Table A.1 to find the file location for your setup.

TABLE A.1 Locating httpd.conf

Setup Method

Configuration File Path

Windows (XAMPP)



Type locate httpd.conf in a shell

Mac OS X Tiger


Mac OS X Leopard



Use the MAMP control panel (Preferences/Apache) or /


In the configuration file, look for a line beginning with DocumentRoot. The path that follows this directive (in double quotes) is the document root. It must not end with a slash (or a backslash). Write down the old directory and enter the new directory here. Then search for the old document root directory until you find a line that looks like <Directory "C:/xampp/htdocs"> (the path is your old document root). Enter the same new path here as well and save the file. This part of the configuration file could look like the following code example:

# 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 "/Users/kkaefer/Sites" [...]

# This should be changed to whatever you set DocumentRoot to.

<Directory "/Users/kkaefer/Sites"> [...]


For the changes to take effect, you have to restart the Apache Web server. To do so, follow the instructions found in Table A.2.

TABLE A.2 Starting and stopping Apache

Setup Method

Restarting the Method

Windows (XAMPP)

Use the XAMPP control panel


Typeapachectl restart or /etc/init.d/

apache restart

Mac OS X

System Preferences/Sharing, uncheck/check

"(Personal) web sharing"


Use the MAMP control panel application


Was this article helpful?

0 0

Post a comment