Using Mac OS X to Serve Web Pages

For most Mac users, a hosting service is the way to go. Hosting services handle the hard work of maintaining the hardware and software that is needed to serve your site to the Web. A hosting service must also deal with all the hacking to which most Web sites are subjected. A hosting service enables you to concentrate on your Web site rather than the Web server that provides it to the Web. Additionally, you can get many other services that make your Web site even more powerful (such as domain name registration).

However, there might be situations in which you want to be your own hosting service. If you have a site that will be accessed in a limited fashion by people outside of your local network, hosting your own site can be an easy and effective way to share information. Also, you can easily host a site that will be accessed through your local intranet.

One of the great things about Mac OS X being based on Unix is that many of the tools available for Unix will work with it as well. And when it comes to the Internet, most of the "back end" runs on Unix, so there are many useful tools available.

Even better news is that Mac OS X includes very powerful and sophisticated Web server software?Apache. 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 do the basic tasks of serving a Web site 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 Web site is beyond the scope of this book. However, in this section, you will learn the basics of hosting a Web site on your Mac, and you will see how easy it is to get started doing so. From there, you'll see pointers to more information so that you can take your Web hosting to the next level.


If you plan to have a very active Web site with heavy traffic, you are going to need a dedicated machine to act as a Web server. In fact, if you want to be serious about hosting a Web site, you are foolish to use your "production" Mac. Bad things can happen to Web servers, so you should never host a Web site from a machine that you also use to do work. (However, this is feasible if your Web site will be accessed only by a few people and will have little traffic.) The biggest threat to a Web server is the hackers who love to break into such servers and wreak havoc. Because your Mac should be directly connected to the Internet to be able to serve a site, it will be vulnerable to attack. If you use your production machine to host Web pages, you are opening yourself up for trouble. This is a prime advantage of using a hosting service because that service has to deal with the security of its hardware and software. There is no direct link between your Web site and your production Mac.

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

  1. Create your Web site using any tools you prefer.

  2. Test it to make sure that it works.

  3. Register your domain.

  4. Move the files for your Web site 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 hours, seven days per week.

For information on some Web creation software, see "Mac OS X to the Max: Web Creation Software," p. 398.

To host a Web site, you need to have the following:

  • A powerful Mac with a large amount of RAM, preferably a dedicated machine that is used for no other purpose. A busy Web site will generate a great deal of activity on the Web server. Don't try to skimp by on a low-end machine or your Web site might be a big flop.

  • A Web server application. Because you are using Mac OS X, you have this one (Apache is built in).

  • A registered domain name. To make it easier for people to find and use your site, you need to register its domain name.


    If you are hosting a site only for a local intranet, you don't have to register a domain name. You can use the IP address of the machine just as well.

  • A direct, high-bandwidth Internet connection. Because the point of having a Web site is so that people can access it, you need to have an "always-on" connection to the Internet. You also need to have high bandwidth to handle all the data that will be moving among many users at the same time. You need to have a fast cable modem for a site on which you don't expect that much activity. You need a T-1 or partial T-1 line for a site on which you expect to have a fair amount of activity.


    Again, you don't need this if you are hosting a site on an intranet. You just need the network connection and an IP address for your machine.

  • Although this goes hand in hand with the previous point, you need to have a permanent IP for the machine from which you will be hosting the site. (After all, how can people find your site if its address changes?) If you can use a static IP address, it will be provided to you by your access provider when you obtain your Net access, such as when you use a T-1 or fractional T-1 connection.

    To learn about connecting your Mac to the Net with a high-bandwidth connection, see Chapter 10, "Connecting Your Mac to the Internet," p. 233.

  • A security system that will protect the Web server. Hackers will try to crack your site so you need to install and use tools to protect it.

Hosting a serious Web site is resource- and labor-intensive, as you can see from this list. (A hosting service looks better and better, doesn't it?)


If you try to host a site from a "consumer" ISP, make sure that your license agreement does not prohibit such activity. For example, many cable modem service providers explicitly prohibit you from hosting a Web site through your Internet access account.

Registering Your Domain

Web sites are designed for people, and people don't like to deal with IP addresses. They much prefer working in letters and, even better, words that make some sort of sense to them. Because IP addresses are actually four series of numbers separated by periods, the two have a hard time getting together. That is where the Domain Name Service (DNS) comes in. Basically, the DNS relates text that people use to the numbers that computers use. When someone enters a URL, the DNS server that they use translates the text that they type into the literal IP address so that they can move to that address.

In order for this to happen for your site, you must enter the domain you want to use and the IP address it is associated with. This process is called registering the domain name.

There are various ways to register your domain name (the easiest is to use a hosting service that also offers domain name registration). You can search the Web to find sites at which you can register a domain name. The fees you will pay vary depending on the length of time for which you register the name and the other services that are included.


Although many companies will register your name free, you usually have to pay the fee associated with the registration. (A fee is charged for each domain name so someone has to pay that fee.) Some companies will charge you to register the name and you will also have to pay the name fee. And some companies will subsidize the fees if you use other services. Does this sound confusing to you? If so, join the club. There are as many fee structures as there are companies doing this, so you just have to make sure that you know what you are signing up for.

When you search for domain name registration sites, you will find many of them. And most offer similar deals. For example, I could register a name for about $20/year. Some even include additional services in this agreement, such as e-mail forwarding.


E-mail forwarding enables e-mail to your domain name to come to your current e-mail address. For example, if I registered the domain, I could have e-mail addressed to delivered to any address that I prefer.


Be sure that you carefully read all domain name registration agreements before you finalize them. There are many reputable companies out there, but there are also many that are not so reputable.

Put some thought into the domain you register because that is how people will find your site. Avoid really long names, no matter how clever you think they are. Simple names are better.

Configuring Your Mac to Serve a Web Site

Each user account on your Mac can serve its own Web site; this means that you can serve many Web sites from your Mac at the same time. To provide a Web site 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.


Each user's Sites folder contains an index.html file that provides a default Home page for that user's Web site. 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).

There is also an overall Web site for the Mac itself. You should also make sure that you add a Web site for the Mac so that when people move to the Home page for your machine, they will see a meaningful site. (You will learn about that shortly.)


A default index.html page is stored in each Sites folder. This page contains information about how Web sharing works and is worth reading if you are new to the topic.

After you have created your site, registered a domain name, and configured your Mac for the connection you are using, the steps to get it online are pretty simple:

  1. Place the files for the site you want to post in the Sites folder of the user account you want to use. For example, if the username under which you want to post a site is bmmiser, open the Home directory for that user and then copy the Web site into the Sites folder (see Figure 14.13).

    Figure 14.13. When a Web page is stored in a user's Sites folder, it can be served to an intranet or to the Internet.


    As with the .Mac site, make sure that the name of your Home page is index.html. You can organize the other files and folders according to the scheme used by your Web-creation application.


    You can test any user's Web site 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 utility and then open the Sharing pane.

  3. On the Services tab, check the "Personal Web Sharing" check box. In the Network Identity area (located at the bottom of the Sharing pane), you will see the IP address of your Mac. 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, the URL to your machine is also If you use the IP address to access the site, it will be resolved to the host name and that is what appears in the address bar of the browser.

    The URL to a specific user's Web site 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 bmmiser, the URL to my Web site would be http://12.34.567.89/~bmmiser/ or

    You will also see the URL to the personal Web sharing pages at the bottom of the window.


    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 need to include the end slash (/) in the URL as well.

  4. Close System Preferences.

  5. Use another machine to access the URL for your Web site.

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


When you attempt to move to a user's Web site, but it can't be found even though the root-level site can be displayed, see "You Can Access Your Root-Level or Other Web Sites, but Not the Site for a Particular User" in the Troubleshooting section at the end of this chapter.


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


If your site isn't found at all, see "Your Web Site Can't Be Found" in the Troubleshooting section at the end of this chapter.

If instead of your Web site, you see an Apache page that says that the Web server is working, see "The Web Server Is Working, but You Don't See Your Site" in the Troubleshooting section at the end of this chapter.

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


Consider creating a Web page that provides URL links to all the Web sites 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 Web site that you want to be at the root level of your machine.

  2. Name the Home page for this site.

  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 that the index file is in this directory.

By default, a test page is placed at this location so that when you move to your root level, you can tell that the Web server is working (see Figure 14.14). This page also contains links to information about Apache.

Figure 14.14. This page lets you know that Apache is up and working on your Mac.



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

Going Further with Apache

The information in this section has barely scratched the surface of Apache specifically and Web serving in general. However, there is a great deal of information on both topics 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 that is within 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 There is plenty of information on this site, including some nice tutorials.


Before you leave this section, I must give you two more warnings.

First, make sure that you protect your Mac from attack if you intend to publish and publicize Web pages you host from it.

For information about protecting a Mac from Net attacks, see "Defending Your Mac from Net Attacks," p. 800.


Second, some ISPs have limitations on what you can do from particular types of accounts. For example, the license agreement you signed with your ISP might preclude you from hosting Web sites using that account. Make sure that you understand any such limitations on your ISP account before you use it to host a Web site.


You can also serve an FTP site from your Mac. On the Sharing pane, check the "FTP access" check box. When you use ftp instead of http in the URLs for your machine, you will move to the FTP site instead of the Web site.

    Part I: Mac OS X: Exploring the Core
    Part III: Mac OS X: Living the Digital Lifestyle