Mac OS X to the Max: Using Mac OS X to Serve Web Pages


You can use Mac OS X to host a website for the Internet or for a local intranet because the web server software you need is already built in to Mac OS X. Serving a website to the Internet is a fairly complex task, and there are many nuances you need to consider. However, serving a website to a local network is fairly straightforward. In either case, you can use Mac OS X to get your site online.

Mac OS X includes very powerful and sophisticated web server softwareApache. This software is widely used across the Internet to serve web pages, and Mac OS X users can take full advantage of it out of the box. Although Apache is a Unix application, you can perform the basic tasks of serving a website without messing around with text commands. Of course, to really customize and master Apache, you do need to get your hands into the command line. However, you can get a site up and running without ever interacting directly with Apache.

Establishing and maintaining a web server is a complex and challenging task, and explaining all the details associated with hosting a website is beyond the scope of this book.

The general process for using your Mac to host a website is the following:

1.

Create your website using any tools you prefer.

2.

Test it to make sure that it works.

3.

Register your domain.

4.

Move the files for your website to the appropriate location on your Mac.

5.

Start the web server.

6.

Monitor your site to ensure that it has adequate performance and is available 24/7.

Each user account on your Mac can serve its own website; this means you can serve many websites from your Mac at the same time. To provide a website for a user's account, you place the files for that site in the Sites folder that is contained in that user's Home directory.

There is also an overall website for the Mac itself. You should ensure that you add a website for the Mac so that when people move to the home page for your machine, they will see a meaningful site.

To start serving a website from your Mac, perform the following steps:

1.

Place the files for the site you want to post in the Sites folder of the user account you want to use. Each user's Sites folder contains an index.html file that provides a default home page for that user's website. You replace this file with your own index.html file to serve your specific site (you can also modify the default index page if you want). The default index.html page contains information about how web sharing works and is worth reading if you are new to the topic.

TIP

You can test any user's website without actually adding web pages to the Sites folder. Because the index.html page is part of each Sites folder, that page is served up for every account. So, if you move to the URL for a user account on your machine, you should see the Mac OS X Personal Web Sharing page. If you do, that means web sharing is working. All you need to do is replace the default content with your content.

2.

Open the System Preferences application, open the Sharing pane, and then click the Services tab.

3.

On the Services tab, check the "Personal Web Sharing" check box. This starts the web server on your Mac. Just below the list of sharing services, you will see the URL of the Mac along with the URL for the user's website. You build the URL for your site based on either of these. For example, if your IP address is 12.34.567.89, the basic URL for your site is http://12.34.567.89/. Similarly, if the registered domain name for your Mac is agreatmac.com, the URL to your machine is also http://www.agreatmac.com/. If you use the IP address to access the site, it is resolved to the hostname and that is what appears in the address bar of the browser.

The URL to a specific user's website on your Mac is the URL for the Mac itself with a ~ (tilde character) followed by the short version of the username appended to it. For example, if the short name for my user account is bmiser, the URL to my website would be http://12.34.567.89/~bmiser/ or http://www.agreatmac.com/~bmiser/ (if I had registered a domain name appropriately, of course).

NOTE

The tilde (~) character in the URL indicates that the address points to that user's Home directory, in which the Sites folder is stored. If you leave this out of the URL, the user's site won't be found.

You also need to include the end slash (/) in the URL.

4.

Close System Preferences.

5.

Use another machine to access the URL for your website.

If you see the site, everything is in great shape and your pages are "available."

TIP

The concept that each user who has an account on your Mac can have a unique website opens many possibilities for you. You can create user accounts for the sole purpose of providing specific websites. For example, if I wanted to host a website for this book, I could create a user account called SEUsing MacOSX with the short name usingosx. I could then place the website in the Sites folder for this account and the site would be published.


If you are going to be hosting any web pages on your Mac, you should also configure the root-level website for your Mac. This site will appear if someone accesses the website on your Mac without including a specific user's account in the URL. For example, if someone enters only http://12.34.567.89/, he would see the root-level web page.

TIP

Consider creating a web page that provides URL links to all the websites that are hosted on your Mac and posting that at the root level. This would make it easy for a visitor to get to any of the sites on your machine.


If you open the directory located at Mac OS X/Library/WebServer/Documents/, where Mac OS X is the name of your Mac OS X startup volume, you will see many index pages. Each of these has an abbreviation for the language for which that page is applicable at the end of its filename (for example, the file index.html.en is the English version of the page). The version that Apache serves depends on how your machine is configured.

To post a root-level web page, do the following:

1.

Create the website you want to be at the root level of your machine.

2.

Name the home page for this site; again, the name of the home page for the site should be index.html.

3.

Place the files and folders for the site in the following location: Mac OS X/Library/WebServer/Documents/, where Mac OS X is the name of your Mac OS X startup volume. Make sure the index file is in this directory.

NOTE

The web server continues to run as long as your Mac is turned on and the website for each user account is served continuously, even if no one is logged in to the system. You can stop the server by shutting down the Mac or by turning off web sharing using the Sharing pane of the System Preferences application.


The information in this section has barely scratched the surface of Apache specifically and web serving in general. However, a great deal of information on both topics is available within Mac OS X as well as on the Net.

To access the Apache documentation included with Mac OS X, open the manual alias in the Documents folder (contained in the WebServer folder). The Apache folder will open. Open the index.html file and the Apache User Guide will open.

To find information on the Web about Apache, visit www.apache.org. There is plenty of information on this site, including some nice tutorials.



Special Edition Using MAC OS X Tiger
Special Edition Using Mac OS X Tiger
ISBN: 0789733919
EAN: 2147483647
Year: 2003
Pages: 317
Authors: Brad Miser

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net