GoLive 5
HomeFree ChapterExample FilesTipsExtensionsLinksAuthorsGoLive 5 Site Opens in New WindowSearch

Creating a Virtual Directory for the
Apache Web Server on Mac OS X

Introduction
In this section we'll teach you how to create a virtual directory for Apache so you can edit and test your dynamic web site locally. It involves some typing in the Terminal application but if you follow the directions carefully we're confident you'll be successful and learn a lot in the process!

Background
When a Web server processes an HTTP request, it uses the URL to identify a specific page. The first part of the URL names the server and port number. The default port number, if none is specified in the URL, is 80 and the Web server listens for requests on that port. There can be more than one Web server running on a given machine, each on a different port. The next part of the URL begins a path name that ends with the specific page name such as http://www.adobe.com/products/main.html.

The first name after the server name, in this example, products, is the first segment in a path name of pages stored on the server. Usually, a particular Web server will host more than one site. The files of all Web sites on the server can be stored in folders in the Web root folder of the server. Alternatively, the folders that hold the Web sites can be placed in other locations in the server's file system and pointers can be created in the Web server configuration that point to the actual folders containing the sites. These pointers are called aliases in Apache or virtual directories in Microsoft IIS and Microsoft Personal Web Server.

You need to decide the name to be used for the alias for your site. A common convention is to use the site name you chose when you created the site in GoLive. For example, if your user name is lgrillo and you created a site "examplesite" in GoLive on your desktop, it ends up in /users/lgrillo/Desktop/examplesite_folder/examplesite. If you create an alias "examplesite" that points to the "examplesite" folder (not the "examplesite_folder" folder), then a browser could reference your site using the URL http://localhost:8200/examplesite. Carefully follow the four steps below to create an alias in the Apache configuration file.

Step 1: Locate and Edit the Apache configuration file
The Apache configuration file you're going to edit is called httpd.conf and it controls how the Apache web server works. The particular change you're going to make is to add a new virtual directory so you can edit and test your dynamic web site.

To find the httpd.conf file use one of these three methods:

  • Double-click the Edit Apache Configuration alias that is placed on your Desktop when you install the GoLive Preconfigured Servers package. This opens the file for you.
  • Open the file at Applications/GoLive_Preconfigured_Servers/php_server/apache/conf/httpd.conf
  • Use Sherlock (Command-F in the Finder) to search for the httpd.conf file

The first time you open the file you may be asked to choose an application in which to open it. Choose TextEdit from the Applications directory.

Step 2: Find the edit location
When the file is opened in TextEdit scroll down near the bottom of the document and look for this:

# Alias for all php test sites
Alias /testsites_php "/Applications/GoLive_Preconfigured_Servers/TestSites/php"
<Directory "/Applications/GoLive_Preconfigured_Servers/TestSites/php">
       Options Indexes FollowSymLinks MultiViews ExecCGI
       AllowOverride All
       Order allow,deny
       Allow from all
</Directory>

That is the syntax for a virtual directory on Apache. Select this text in TextEdit and choose Edit>Copy. Then place your cursor on the line after </Directory> and choose Edit>Paste.

Step 3: Edit the configuration file
Now you need to edit the current file path with the file path to your site. Make sure the path goes all the way to the root folder of your site, not just the enclosing folder. Here's an example of a virtual directory for a site called examplesite and saved on the Desktop. The text in red shows what was changed to create this new virtual directory.

# Alias for examplesite
Alias /examplesite "/Users/lgrillo/Desktop/examplesite_folder/examplesite"
<Directory "/Users/lgrillo/Desktop/examplesite_folder/examplesite">
       Options Indexes FollowSymLinks MultiViews ExecCGI
       AllowOverride All
       Order allow,deny
       Allow from all
</Directory>

Now let's dissect this to learn what we've just done:

--------------| line 1 |----------------			
# Alias for examplesite

This line is just a comment and is optional. It's a good idea to keep it because it will help you to recognize the various virtual directory entries quickly and easily.

--------------| line 2 |----------------
Alias /examplesite "/Users/lgrillo/Desktop/examplesite_folder/examplesite"

The part in blue is the name of the virtual directory and you can think of it as an alias. Choosing a name for the virtual directory that matches the name of the site you are working on is a good idea but not technically required.

The part in red is the path to your site's root folder. If any of the folders along the way contain spaces we strongly recommend you go back and change them to underscores. If for some reason you really must use spaces, you must translate them to %20 in line 2 or it will not work. The easiest way to make sure this path is correct is to open the Terminal application inside the Applications/Utilities folder and then drag and drop the root folder of your site into the terminal window. This will give you the full path which you can then copy and paste into the httpd.conf file using TextEdit.

--------------| line 3 |----------------
<Directory "/Users/lgrillo/Desktop/examplesite_folder/examplesite">

Again, replace the part in red with the path to your site's root folder. This should be the same as in line 2.

--------------| the rest |----------------
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Unless you need to set access in a specific way you can leave the rest of this as is. If you want more details on the exact meaning of these options, the Apache documentation is included as part of the GoLive Preconfigured Servers package. See http://localhost:8200/manual/mod/directives.html for a list of all of the directives and their meanings.

Save the file, close it, and quit TextEdit when you are done making the necessary edits.

Step 4: Restarting the Webserver
You must restart the Apache web server before it will recognize the new virtual directory. Restart the server by double-clicking the Restart Webserver alias on your Desktop.

Conclusion
Once you've done this once or twice the process isn't quite as intimidating. You only need to create a virtual directory using these steps when you create a new web site that uses the GoLive 6 Dynamic Content features. For more free tutorials, tips, and tricks visit the Tips page.

Home | Free Chapter | Example Files | Tips | Extensions | Links | Authors | GoLive 5 | Search

Contact the authors via email: authors@golivein24.com