Apache Webserver On Mac OS X 10.8+


I have recently started to use my Apple Macbook Pro for learning / building web applications using HTML5, CSS, JavaScript etc.   To test these apps, I needed a web server, and it makes complete sense to use the most popular server – Apache.

Having visited the Apache website, I soon discovered that there is no native download for the Apple Mac…  with some help from a web search, it turns out that Apache web server is already part of the standard OS X build 🙂

To use the Apache server, I had two challenges :-

  1. Configure the server
  2. Understand how to start / stop the server.

Browsing through Getting Started section of the documentation, I found that the Apache server uses configuration found in a file named httpd.conf   On OS X, this can be found in the /etc/apache2 directory.  To make changes to the configuration e.g. set a document root, change virtual hosts, add additional module to load this file must be edited and using a basic editor such as TextWrangler works really well (if you enjoy working in Terminal, you can also use vi or emacs 😉  ).

The main piece of information you need is where is the document root – this is the directory into which all documents / sub directories etc that you will create go.   You can either find this by editing the httpd.conf and select the Search Menu, then Find in TextWrangler – enter “DocumentRoot” and select Next.   You should see something like :-


 # DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot “/Library/WebServer/Documents”

So, the /Library/WebServer/Document folder is where you can store your web pages / applications – to make it easier to navigate to this folder, I used the OS X Finder to add a shot cut into the side bar.

Now that the web server is configured, the second challenge is knowing to start, stop and restart.   

To do this, I use the OS X Terminal application, and the following commands :-

sudo apachectl start

sudo apachectl stop

sudo apachectl restart

As you will see, the server is managed as the root user, so when starting the server you will be prompted for your password (the same as you use when starting . logging into OS X).

To test the server is working, open your browser and access your local ip address (127.0.0.1) – you should see a message “It Works !”

 

One thought on “Apache Webserver On Mac OS X 10.8+

Comments are closed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: