macwebserver

Foreword v2

Please note that the following document is not new and not necessarily up to date. It should however still work in the intended systems, those being Macs with a Classic system (7, 8 or 9).

Foreword

I wrote this tutorial because I wasn't able to find any good information on the internet about setting up a web server on a Mac, and so I sat down and did it.

I would appreciate any comments or suggestions about this page. Please send them to lasar@liepins.de Thank you.

Intro

The page title says it all. However, I am concentrating on web servers used for testing sites and (most importantly) Perl CGIs without having to connect to the internet and uploading your files.

To understand this tutorial you should have some experience with the Mac OS, you should know how to click, where the Control panels are, and such simple things. I don't ask you to be a computer expert, but some basic knowledge is required. Thank you.

What you need

A Mac
It is not very important what kind of system you have. If it can run System 7, it should be able to work as a web server. However, this tutorial is based on Mac OS 8 and 9 and the included web server controlpanel.

The TCP/IP control panel
This is where you tell your computer where to look for other computers, where to get the address at which it is accessible from others, and such things.

AppleTalk
Should be installed on your Mac, unless you decided to throw it away.

A Web server
Since you want to serve web pages, you need a web server. There are several web servers for the Mac out there, some of them shareware or freeware, others are commercial products.

If you want to run Perl CGIs, you will also need MacPerl, a free Perl interpreter for the Macintosh.

Depending on what you want to do with your web server, and who you want to see your web site, you'll need other things, like a permanent connection to the internet, if you want to have your site visible on the whole internet (in this case you'll also need a domain name and some more things), or a connection to your local computer network in which the pages will be used. I can't help you with these, as I don't have experience in this field (yet).

Let's get going

Launch the Chooser. It should be in the Apple menu. Activate AppleTalk by clicking the upper radio button in the lower right corner. Close the Chooser.

Open your control panels folder.

Open the TCP/IP control panel. Select User Mode from the Edit menu, and set your mode to Administrator. Return to the control panel. From the Connection popup, select AppleTalk (MacIP), from the popup menu right under it, select MacIP manual. Enter the IP under which you want to be available to the connected users into the text field IP-Address. For this tutorial, we'll use 12.34.56.78 . The IP must consist of 4 numbers between 0 and 255, with dots between them (Examples: 123.456.789.123 , 0.0.0.0, 255.255.255.255, 42.42.42.0 , 192.465.54.7). If You want your computer to also be available under a proper domain name (like www.local.net), you will have to go through the steps detailed below.

Now, open the Web Sharing control panel. Click on the Select button next to Web-Folder to select the folder which contains your web pages, and the starting page. Select the radio button entitled "Users can read only". Now hit the Start button. If everything went well, the button will change its name to Stop, and some seconds later your IP address will appear next to "My Address". Don't let it bother you that the domain name you selected (if you did so) does not appear here, it should work anyway.

Now comes the moment that should bring a very big grin to your face. Open your web browser of choice, enter 12.34.56.78 or www.local.net into the Location field, and hit enter. The web page you selected earlier should appear on your screen. Congratulations. Invite your friends to a "My First Web Server Party".

Get your own domain name, free!

Launch a text editor, like BBEdit or SimpleText. Enter the following text into an empty document:

www.local.net   A       42.42.42.0
local       CNAME   www.local.net

Change the IP address to the one you entered into the TCP/IP control panel, and enter any domain name you care to use. I will use www.local.net in this tutorial, though. Note that this will not give you the domain name on the internet. It will only work in your offline environment. Save the file anywhere you like (the system folder or your web folder may be a good idea), under any name you like. The standard here seems to be "Hosts" (without quotes), but it doesn't matter, really. Go back to TCP/IP, and click on the Select Host File button. Navigate to the place where you saved the file, and select it. You can now close the control panel. Note: Whenever you change the text file, you will have to reselect it in the control panel, otherwise the changes will go by unnoticed. You can enter multiple domains for different IPs (if you have several computers with web servers on them networked, like me), or even for the same IP.

A final tip, you might also want to read the official Personal Web Sharing documentation, which should be somewhere on your mac, unless you trashed it.

Addendum: Richard Honea (thanks!) told me that he was unable to get the domain name to work until he put both lines on a single line, like this:

www.local.net   A       42.42.42.0     local       CNAME   www.local.net
Run Perl CGIs

I won't teach you what Perl or CGIs are, and I also won't tell you how to program them. I will only tell you how to set up your web server to execute them.

If you don't have it already, go and download MacPerl from the MacPerl home page (the link is listed in the links section). Install it anywhere on your hard disk, there's no need to configure anything.

Now you'll need a Perl script. If you don't have any already, use this one for testing purposes:

#!perl

print "Content-type: text/html\n\n";

print "Hello World!\n";

Launch the MacPerl application, select New from the File menu, and copy the code into the new window. If you have your own script, you can just open it from MacPerl (if it is in text format). Now Save the file. In the Save dialog box, select CGI Script from the popup menu at the bottom. Name it test.cgi and save it inside your web folder.

Your second great moment has come. Switch to your web browser, and go to the URL under which the script is located, e.g. http://12.34.56.78/test.cgi or http://www.local.net/test.cgi . The Text "Hello World!" should appear in your browser.

Note: Most Perl scripts found on the internet (a great resource for CGIs in general is the CGI Resource Index) were written to run on Unix/Linux machines. They won't work on Macs without modifications. Read the documentation found at the MacPerl web site or in the docs that come with it to learn what you have to change.

Links

www.apple.com - Apple Inc.

www.macperl.org - Home page of MacPerl

The CGI Resource Index

Credits

Thanks to Democco Atcher for asking how to set up a web server, which motivated me to finally go and write this tutorial, something I wanted to do all along.

Thanks to Apple, Inc. for the obvious.

Thanks to Matthias Neeracher for writing MacPerl.

lasar@liepins.de © 1998-2004 _Lasar Liepins

© 1998 - 2008 Lasar Liepins