eXtensions
Setting Up your Own Webserver on OSX with Apache |
It is becoming increasingly common for small offices and even homes to have their own networks, whether connected by Ethernet or by broadband wireless: in the Mac this is called Airport.
Particularly for a small business, the sharing of information has a high importance. It is possible to link Macs together, as well as Macs to PCs and access individual folders where files may be stored. Far more elegant, however, is the creation of an intranet: using OSX and the Mac as a web-server.
While this was possible in System 9, the hoops one had to leap through to make it all work made one wonder if it really was a Mac. In OSX the value of its UNIX base means that one of the prime means for web-hosting -- the Apache web-server -- is available as part of the operating system.
The way in to Apache, is via System Preferences and the "Sharing" section, in the Internet and Network section of the main System panel. Within the Sharing panel are three tabs: Services, Firewall and Internet. The Internet tab allows others linked to your machine via a network to have access to the Internet.
Services contains the "on buttons" for several valuable functions: Personal File Sharing, Windows File Sharing, Remote Login, FTP access, Remote Apple Events, and Printer Sharing. To activate any of these, tick the box alongside the service, and then click the "Start" button just to the right.
Of these, I only have Personal Web Sharing activated. I have done this on both the home G3 iMac, which is standalone, and on my office G4, which is connected to a network and has its own IP number.
With any of these services, turning them on opens the door to outside users. The second tab in the Sharing preferences is for a firewall. By clicking the Start button access is denied: all boarders are repelled.
This is a contradictory situation: you are inviting people in, then preventing them from having access. The firewall has several settings to allow for this. By selecting certain of these -- I only have web sharing ticked -- access from outside is limited only to those areas on the hard disk where the specific, required files are to be found.
The Firewall preference has a couple of additional buttons for fine-tuning: "edit" and "new". None of the installed settings can be edited: trust me, I tried. "New" however, allows access to a whole range of settings. Among these were ICQ, IRC, SMB (Samba) suggesting that the services that can be run from the desktop Mac are fairly wide; and with no additional software to be begged, borrowed, or otherwise acquired.
Having started the Personal Web Sharing, and turned on the Firewall, typing http://localhost/~username/ will produce a file written by Apple welcoming a user to the service.
In that URL above, the essentials are the "localhost" location, a tilde, the user's login name, and then finally another back-slash. On my home iMac, I enter http://localhost/~gkrogers/
The files for this site are kept in a specific location: the "Sites" folder. This is inside my username folder (gkrogers), which can be found in the "users" folder on the hard disk. With this structure, it is possible for all those who have accounts on the computer to have their own web site: like settings and account preferences for applications, these are all isolated from each other.
On a network, the approach is slightly different. The home machine -- not on a network -- does not have an IP number, so "localhost" suffices. If the computer is networked, then IP numbers will have been allocated -- something like 10.10.36.223 -- and these same numbers are entered for a browser to access the page. In the example, if my iMac were on a network, instead of http://localhost/~gkrogers/ (above), I would enter http://10.10.36.223/~gkrogers/ and this would access the index.html file in my Sites folder in exactly the same way.
As well as the user acounts, it is possible to make the computer itself a webserver with none of that untidy entering of names. In this instance, the files (starting with index.html) are kept in a different location in the Library folder, where there is a folder called "WebServer".
If you enter http://localhost/ (with no user name) in the browser, instead of an Apple welcome, pages introducing Apache itself are accessed. The index.html file will need to be changed to make the computer a personal web-server, I moved these files as they contain much useful information and replaced them with a rewritten index page from my own website. A directory structure for the pages and links os then created within that WebServer folder.
As Apache is a real web-server, it has some real functions that can be accessed. Although these are not turned on by default, with a bit of work in the Terminal, it is possible to open the configuration file and turn on CGI scripting, Server Side Includes (SSI), PHP for dynamic web content, and WebDav for file sharing and collaboration. This is not for the faint-hearted nor for the unskilled.
I debated with myself whether I should provide some of the details of how these operate, but reminded myself that a little information is a dangerous thing. You may know how to do this already; or you may be interested enough to find out; but you may do some damage if you are not careful. Apple has proved the essentials and most will be content.
On a computer that is networked, the files will not usually be visible to those who are in the outside world. LANs are either completely cut off from the Internet, or protected by strong firewalls. To have your personal computer link to the real world might take some delicate negotiations with the System Administrator.
Within an office environment, however, it is certainly possible to share data with those on the same LAN and, for example, this could assist those interested in working towards the paperless office.
I have another use for the webserver environament on my home iMac. By using the /localhost/ environment, I am able to set up a test bed for a website in preparation for a move to a site with considerably more disk space. Over the years, my page locations have become a bit haphazard and this allows me a realistic way to replan the whole site before uploading the pages to the new site.
Further information on Apache may be found at the Apache website and on Apple's web pages.
For further information, e-mail to Graham K. Rogers.
Back to
eXtensions
Back to homepage