Running a local webserver on a Mac

David Ramos (ramos@american.edu)


Usually, you can open a file directly in a web browser, from a file:// address. Some scripts and embeds will only work when an HTML file is being served from a webserver, over an http:// address. You can either put your site on a server somewhere on the Internet, or you can run a simple server on your own computer. Here’s how to run a very basic webserver on your Mac.

Open your website folder in the terminal

  1. Open Terminal.app. One easy way to find Terminal.app is to search for it using the Spotlight menu (the magnifying glass on the right side of the menu bar).

  2. In the terminal window, type cd, followed by a space. Don’t hit return yet.

  3. Go to the Finder. Select the icon for the folder that contains your website. Drag that icon into the terminal window. Your window will now show a line that looks something like
    cd /Users/studentname/foldername/projectname.

  4. Press Return. The cursor will drop to a new line and you’ll have a new prompt on the left side of the window.

terminal window screenshot

Run the server

  1. Type python -m SimpleHTTPServer 8000 into the terminal and hit return.

  2. The terminal will say Serving HTTP on 0.0.0.0 port 8000 ....

  3. You can go to http://localhost:8000 in a web browser to see your website.

Quit the server

  1. To quit the server, press Control-C. You can then close the terminal window.

Updated 2017-01-02