Rolling Your Own Webserver – Part 5

This time, I’m going to try to explain how to set up a very simple webserver using Personal Web Sharing for MacOS X.

Personal Web Sharing in MacOS X is “personal” in name only. The built-in web server that comes with every copy of MacOS X is the industrial strength open source product, Apache. Apache runs on more webservers than just about any other product out there. It is scalable, extensible, and works with virtually every web scripting language out there, including HTML, PHP, Perl, Javascript, Ruby on Rails, Ajax, Python, and many more, but that’s waaaaay beyond the scope of this blog.

Setup couldn’t be easier. To activate Apache, go to System Preferences>Sharing. Make sure the Services tab is selected. See example below. Click the checkbox for Personal Web Sharing. You will be prompted to enter your administrator’s password. In a moment, Apache will be up and running.

To verify the firewall has been configured correctly, click the firewall tab in the Sharing window (see example below). The Personal Web Sharing checkbox should have been enabled by default.

Your webserver is now running! Wasn’t that easy? Now, what do you do with it, and where do you put your files? Let’s move back a bit, and let’s turn the webserver off while we do some simple setup.

At the top level of your hard drive (by default, it’s named Macintosh HD, but you could have named it something else…), open the Library>WebServer>Documents folder. Your website normally is placed in the Documents folder at this location. Alternately, you can set up what’s called a “personal website” within your Sites folder, at path Users>username–your account>Sites (for example, Macintosh HD>Users>LarryGrinnell>Sites). The difference is how you would access the site from the internet.

Using the first example (the Documents folder), also known as the computer’s website, you would use the URL http://192.168.2.2/, while the second example (your personal website) would be http://192.168.2.2/~LarryGrinnell/. Please note that the IP address and user account are examples only. When you activate Personal Web Sharing in the Services tab of the Sharing window, you will see the exact addresses for both options toward the bottom of the window (which I have obscured in the example graphics). Clicking the first example link in the Services tab of the Sharing window, you will be taken to an Apache home page. Clicking the second example takes you to a Personal Web Sharing home page. Either link shows the server is functioning.

To set your website up for outside use (why else would you be setting one up?), use the first example–the “computer’s website.” Obviously, you don’t want to broadcast a website with just the Apache demo page as your content. You want to create your own content. Hopefully, you were working on that long before you began planning on the hardware/software equation. You will need to write your web pages in HTML. You can do so with a number of excellent commercial tools, including iWeb (part of the iLife package), Dreamweaver, GoLive, Freeway, PageSpinner, and more. There are also plenty of freeware, open source, and shareware products out there. Check out versiontracker.com for more information.

If you want to “roll your own”, by writing your own HTML code, my favorite book of all time is Creating Cool HTML 4 Web Pages, by Dave Taylor. I think I have that coded so MyMac.com will get something if you order through this link. I have used this book for years. For me, it was the clearest, easiest book that had all the most-used functions in one place, and I bought a lot of them. It shows the standard method in which you arrange your HTML files (HTML files at the top level, and graphics in an “images” folder), which helps you organize your files. It taught me how to easily make tables and forms–something that had given me problems for years. I have given this book as a gift to many budding web authors. For a computer book to remain in print for over five years is amazing–this book deserves remaining in print.

Because OS X is using Apache, and has a whole library of tools preinstalled for your use, including PHP, MySQL, Perl, and such, with mostly free open source software, you can create very powerful and professional websites. You can create your own blog site with software like WordPress, Movable Type, and so many more (see a list of open source and commercial blog packages here). You can also build a complete web content management system that includes user forums, photo galleries, news, articles, download areas, and more. Use this link to get more information. For my own website, I am using an open source (free) web content management system (CMS) called PHP-Fusion, that offers all that I need to support a family genealogy society, the Grinnell Family Association of America. I am also using another specialized package, The Next Generation of Genealogy Sitebuilding that permits me to publish the complete linked Grinnell family genealogy, containing the names and data of some 30,000 individuals, and 10,000 families–all on a rather modest 1.25 GHz G4 Macintosh mini with only 512 MB of RAM.

There are several additional books that are very useful in helping you set up your own webserver. I like Mac OS X Power Hound, as well as a very detailed series of articles on the O’Reilly website (not all are up to date, but all are useful):

These are but a few examples of what you can do with your own website running on your own Macintosh at your own home. It’s fun and can be very rewarding. As always, please feel free to post questions in the comments area of this blog, and I’ll be happy to try to answer your questions.

Leave a Reply