by Kyle D'Addario
& Wincent Colaiuta
Turning Mac OS X Into A Web Server
April 6th, 2001
Now that you have been using OS X for a few weeks and are likely growing more comfortable with it, we can take a look at some of the very neat features that Apple has bundled with the new OS.
OS X's Unix core means that the OS is well equipped to handle industrial strength, OS reliant tasks such as ftp and Web serving. Apple has kindly provided a very simple way to access both features in OS X, but this week we are only going to talk about Web serving.
A Web server is a computer that sits patiently waiting for users to request documents (like HTML files) and images that reside somewhere on its hard drive. As you know, the World Wide Web essentially knows no time or space boundaries, meaning that a Web server must run reliably 24 hours a day, 7 days a week. Most of this also happens without a system administrator having to intervene all that frequently. When put in this perspective, the responsibility of a Web server is enormous. It must run, all the time, with almost no human attention. Attempting to use Mac OS 8/9 as a Web server, for just that reason, was often problematic if not impossible. While it can be argued that the traditional Mac OS is more stable than its consumer oriented Windows counterparts, system problems and crashes were often far too frequent to use it as a Web server.
OS X does not suffer from such limitations.
OS X's Unix architecture is the same that runs nearly all modern day Web servers. Combined with the flexible and powerful Apache Web Server software, OS X is ready, out of the box, to host your Web site. Some non-OS related limitations include the amount of bandwidth you have available. Not only does the computer need to be on all the time, it needs to be actively connected to the Internet all the time as well. With the wide spread adoption of broadband connections like DSL and cable, this is often not as much of a problem as it once was. So, you have OS X, a fat pipe to the Internet, and you want to host some Web pages; what do you do next?
How Do I Set Up Web Sharing?
This is remarkably easy with OS X's interface for Apache. To enable Apache, users need to simply check a few boxes in Apple's System Preference area. Following is step-by-step run down of how to activate OS X's built-in Web server.
- Open OS X's System Preferences application.
- Choose the "Sharing" setting.
- Under where it says "Web Sharing," click "Start"
- If this works correctly, the window should now say "Web Sharing On" and the "Start" button has turned into a "Stop" button.
The Sharing preferences in your System Preferences.
(Click the thumbnail for a larger image.)
That is the basic part of it. Once you follow the above steps, your OS X computer is ready and waiting to be a Web server. But how do you get to it? Where do you put your HTML files?
At the bottom of the Sharing window under System Preferences you will see your system's current IP address (provided you are connected to the Internet). This is the "phone number" for your computer that other people can use to contact it. If you want to see proof that your computer is set up as a Web server, enter the IP address into a Web browser in this format: http://126.96.36.1994 or whatever your IP address is. You will now be connected to your own Web serving computer.
Where Do I Put The Actual Web Site?
All of your Web site documents are stored in the Documents folder inside your Web Server folder. The full path is: computer/osx/library/webserver/documents
A number of files already reside in that folder. The first page that a Web browser looks for in a directory on any Web server is a file called index.html. If you look in your Documents folder in your WebServer folder, you will see a number of files that read "index.html.en" or something similar. To create a "home page" for your Web server, change the file that reads "index.html.en" to "index.html". Once you do this, go back to your Web browser and click the Refresh or Reload button. Now, if everything has gone right, you should see a page that looks like this:
The default Web page displayed
when you successfully install Apache.
(Click the thumbnail for a larger image.)
But I Have a Changing, or Dynamic, IP!
The single biggest problem for setting up your personal machine to function as a Web server is that most users have an IP address, or "computer phone number," that is always changing. This type of IP address is called a Dynamic IP, and can be problematic for establishing a Web site. Imagine if somebody tried to call you but your phone number changed every day? Now you see the problem.
Fortunately this can be corrected with a free service called dyndns.org. This service, combined with the free application DNSUpdate, allow users to set a "plain English" URL that is always mapped to their current system, regardless of what the current IP address is. This works by DNSUpdate sending a message to the dyndns.org servers every time your dynamic IP is changed. The dyndns.org servers then correctly map your most current IP address with whatever URL you decide to use. So, for example, you might be able to use the URL: osxiscool.dyndns.org
If the system is set up correctly, and you install the DNSUpdate client on your OS X computer, that URL should always reach your machine.
This is, of course, the most basic set of instructions for getting your new OS X computer running as a Web server. There are a large number of security issues to consider, and then there is the small matter of actually designing a Web site. However, if you are feeling motivated, this should get you headed in the right direction.
- Kyle D'Addario
You are encouraged to send Richard your comments, or to post them below.
Most Recent Hot Cocoa Columns
Mac OS X & Firewalls: Part One - The Basics
Console Yourself: Understanding Mac OS X Logs
Making NFS Work On Mac OS X
Hot Cocoa Archives
Back to The Mac Observer For More Mac News!
Kyle D'Addario is the assistant editor of The Mac Observer and has logged about as much time on Mac OS X as is humanly possible. Kyle studies Computer-Mediated Communication, whatever that is, at the graduate level, and was a founding member of the original Webintosh team.
Wincent Colaiuta runs Macintosh news and criticism site, wincent.org, and joined The Mac Observer team as a contributor in March 2001. He has worked with computers since 1984, and his interests in that area include Macs, PHP programming and security.