Running a local webserver on a Mac
GDES-220 spring 2016 · American University Design
Instructor: 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
-
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).
-
In the terminal window, type
cd
, followed by a space. Don’t hit return yet. -
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
. -
Press Return. The cursor will drop to a new line and you’ll have a new prompt on the left side of the window.
Run the server
-
Type
python -m SimpleHTTPServer 8000
into the terminal and hit return. -
The terminal will say
Serving HTTP on 0.0.0.0 port 8000 ...
. -
You can go to http://localhost:8000 in a web browser to see your website.
Quit the server
- To quit the server, press Control-C. You can then close the terminal window.