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)

C:\xampp\apache\conf\httpd.conf

Linux

Type locate httpd.conf in a shell

Mac OS X Tiger

/private/etc/httpd/httpd.conf

Mac OS X Leopard

/private/etc/apache2/httpd.conf

Mac OS X (MAMP)

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

Applications/MAMP/conf/apache/httpd.conf

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"> [...]

</Directory>

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

Linux

Typeapachectl restart or /etc/init.d/

apache restart

Mac OS X

System Preferences/Sharing, uncheck/check

"(Personal) web sharing"

Mac OS X (MAMP)

Use the MAMP control panel application

(Preferences/Apache)

Was this article helpful?

0 0

Post a comment