Restore Web Sharing in Mountain Lion
The Mac OS has had a web server bundled with it since Mac OS 8 debuted in 1997. Traditionally, Apple has referred to the included server software as Personal Web Sharing or just Web Sharing. While little is known about the web server that shipped with OS 8 and OS 9, OS X has included Apache, the most popular web server in the world, which is capable of far more than "personal" sharing - ever since version 10.0 (or earlier, if you count developer versions and the Public Beta).
At first glance, it appears that OS X 10.8 Mountain Lion breaks with tradition and ships with no web server.
It turns out that Apache is still alive and well in Mountain Lion, but Apple has chosen to remove its checkbox from the Sharing pane in System Preferences. Why they have done that is anyone's guess; my personal supposition is that hardly anyone used the built-in Apache in OS X, And I imagine the Web Sharing checkbox probably confused more than a few OS X users who were looking to turn on Internet Sharing, which can route your Internet connection from one network port to another - in from WiFi and out to ethernet, for example.
Whatever the reason, I was more than troubled after I installed Mountain Lion and went to do my normal OS X tweaking. I always like to have Apache, PHP, and MySQL up and running on all my Macs so I can do some quick web testing - or even install a web-based app I might like to have around for personal use. The good news is that Apache is alive and well in Mountain Lion, despite a lack of a way to enable it in the GUI. A quick trip to the Terminal will get you serving web pages once again.
The relevant Terminal command is called apachectl, which is short for "Apache control". When combined with the old standby sudo, which allows us mere mortals to run commands as the all-powerful Unix user "root", Apache web sharing is started in Mountain Lion (or any previous version of OS X, if you are so inclined):
sudo apachectl start
You will be prompted for your OS X password (your account needs to be "Administrator" status to use sudo), and Apache will fire up in the background.
With Apache started, fire up your web browser of choice and enter the URL http://localhost/ and you should be presented with a page that says simply "It works!". Indeed, this is your verification that Apache, version 2, is up and running on your Mac.
As with previous versions of OS X, the directory that serves up web pages is /Library/WebServer/Documents/. Place your HTML files in there and watch them get served up in your web browser.
If you want to stop Apache, take another quick trip to the Terminal, and enter - you guessed it:
sudo apachectl stop
There's also another option for apachectl besides start and stop - graceful, which waits until all open connections to Apache terminate before restarting the server. When running a personal web server, with yourself as the only client, you're not likely to benefit from this command; plain-old stop will suit your needs just fine.
As has become the norm for OS X (and Linux and other modern, user-friendly Unix-based operating systems), someone quickly developed a GUI app to run these commands for you. OS X and Web development firm Click On Tyler has whipped up the Web Sharing preference pane. This gives you a nice toggle switch in System Preferences for turning Apache on and off, just like previous versions of OS X had in the Sharing pane.
But what about enabling PHP and installing MySQL? This requires more Terminal work, which I'll cover in the next edition of Plays Well with Others. So while the System Preference pane is nice, you might as well get comfortable with the Terminal, because we'll be taking yet another trip back there next time so that we can serve up dynamic PHP files, rather than static HTML, and also link up the MySQL database server to PHP in Mountain Lion. (And a third part of this series will look at MAMP, which bundles its own Apache, PHP, and MySQL for a completely Terminal-free experience.)
Recent Plays Well with Others articles
- How to Install and Configure MySQL in Mountain Lion, 2012.08.22. MySQL doesn't come with OS X, but it's free, easy to install, and very powerful.
- How to Enable PHP in Mountain Lion, 2012.08.08. How to enable the PHP scripting language on your Mac running OS X 10.8 Mountain Lion.
- Steve Jobs in His Own Words, 2011.10.06. Steve Jobs spoke his mind, carefully choosing his words for maximum impact.
- More in the Plays Well with Others index.
Links for the Day
- Mac of the Day: Centris 610, introduced 1993.02.10. This was the Mac we used when we started Low End Mac in 1997.
- May 24 in LEM history: 99: Mac sales up, iMac sales down? - 01: Speeding up digital photography - 02: The Internet, research, and plagiarism - 04: NewerTech TiBook battery - Optical mice from Contour - 06: Power Mac today or Intel tomorrow? - 07: G5: Apple's last fling with PowerPC - G3: From 233 MHz to 1.1 GHz
- Support Low End Mac
Recent Content on Low End Mac
- World Book Encyclopedia 2012 DVD, Tommy Thomas, Reviews, 2013.03.05. "You may be asking yourself, in an age of Wikipedia and instant information, is World Book still relevant?"
- Vintage Computer Festival SouthEast, April 20-21, 2013, Simon Royal, Mac Spectrum, 2013.02.25. Old Apple gear and old PCs.
- iMessage: The Ultimate Messaging Service?, Simon Royal, Mac Spectrum, 2013.02.21. In most ways, Apple's iMessage is far superior to BlackBerry Messenger.
- More links in our archive.
- Best Mac mini Deals
- Best 13" MacBook Pro Deals
- Best Intel iMac Deals
- Best iPod touch Deals
- Best iPhone Deals
- Best iPod nano Deals
- Best iPod classic Deals
- Best Apple TV Prices
- More deals in our archive.
Low End Mac Reader Specials
Cult of Mac
Shrine of Apple
The Mac Observer
Accelerate Your Mac
The Vintage Mac Museum
Mac Driver Museum
System 6 Heaven
System 7 Today
the pickle's Low-End Mac FAQ