Apache Web Serving with Mac OS X



Its a known fact that Apple Mac OS X comes packed with the powerful Apache Web Server built-in with other additional goodies neatly packed under the hood.

Mac OS X Tiger carries Apache 1.3 in it. The latest iteration in the OS X line, Leopard comes packed with Apache Version 2.2. In this post we would see how to start the web server and playing with other features.

A Little intro on Apache:

Apache is regarded as the most popular web server available today. With its incredible portability and support for anything you’d ever want to do, Apple wisely decided to ship Apache with its Unix-based operating system. With this web-serving powerhouse at your fingertips, you’ll be able to develop curring-edge web apps using some of the latest technologies like PHP, Ruby, Python etc. More on Apache here

Starting the Web Server:

The simplest way to start the web server is to open up “System Preferences” and click on “Sharing”. Many options are given in this panel, for our effort we will click on “Personal Web Sharing” selection box. The OS timely responds by declaring Personal Web Sharing On. Please see the images below:

Tiger Sharing Panel

Tiger Sharing Panel

Leopard Sharing Panel

Leopard Sharing Panel

If you see the instructions on the Tiger panel, “View this computer’s website at http://192.168.15.2/ or your personal website at http://192.168.15.2/~munirsalman/”. The message is defining 2 sites, the first Apache default welcome screen and the other is the user homepage. Screens of both Tiger & Leopard versions are previewed below.

Apache Tiger

Apache Welcome Screen

Apache Home Page Tiger

Tiger

Apache Home Page Leopard

Leopard

You can also call up your web server by entering http://localhost or http://127.0.0.1 and trailing it with your short name like /~munirsalman/

In the same way, as we “Started” the apache web service through the Sharing panel, we can stop by clicking on “Stop” button.

A little bit of Terminal:

As I said earlier Mac OS X neatly contains so many hidden gems and another of them is the Terminal App. Located under Applications > Utilities > Terminal, this is the Dos prompt equivalent of Windows, but here you are playing with fully loaded and rock soild Unix. BASH Script is used in terminal and people who are familiar with Unix/Linux knows that we can do almost everything from there, actually more than what we can do in the slick Mac GUI. One such example is of Starting, Stopping and Restaring the Apache Web Server. The following commands can be alternatively used to perform the mentioned tasks:

  • Sudo apachectl Start (start Apache Web Server)
  • Sudo apachectl Stop (stop Apache Web Server)
  • Sudo apachectl Restart (Restart the Web Server)
  • Sudo apachectl Graceful (Restart the Web Server, Gracefully)
  • Sudo apachectl Configtest (Expect a response “Syntax OK” if everything is running fine)

What is Sudo?

To perform certain tasks, Root user privileges are required such as restarting the Web Server. Therefore command needs to be entered like Sudo apachectl …. . Upon entering the command, the terminal requests for Password, which would be the Password you have entered for your Mac book.

My Web Location:

Now, we have ourselves one powerful Web Server running. Its time to put something of our own stuff for view. All your web pages are stored by default at:

/User/Username/Sites

If you put a file lets say “Hello.htm” with hello world in it, the following path will be used to call it:

http://localhost/~munirsalman/hello.htm

So we are done with hosting static pages and basic level hosting, in my next post we’ll start with powering up some PHP code.

One good reference link from Apple on Web Dev

Tags: , , , , , , , , , , ,



Hi, Stranger! Leave Your Comment...




Name (required)
Email (required)
Website
Message