-
Notifications
You must be signed in to change notification settings - Fork 6
Local Server Tutorial
We'll be using the command line regularly in this class. Nothing too fancy; just the basics. Get familiar, at the very least, with the commands ls
, cd
, and mkdir
. This will help.
-
Open up a Terminal Window. (If you've never used the Terminal before, hit command-space and start typing "Terminal". Click on Terminal and a Terminal window should open.)
-
Navigate to the directory (i.e.folder) where your files are saved. An easy way to do this is to type
cd
and then a space and then drag and drop the folder (where your files live) on top of the terminal window. The path to this folder (directory) should appear. Then click enter. -
After clicking enter, you can type the command pwd to see exactly where you are in terms of your directory structure
-
Next, check your version number of python (python comes preloaded on Macs) by typing the following command into the Terminal window and then hitting enter:
python --version
If you are running version 2 (i.e Python 2.x.x) type the following command and then hit enter:
python -m SimpleHTTPServer 8000
If you are running version 3 (i.e. Python 3.x.x) type the following command and then hit enter:
python -m http.server 8000
- You may (or may not) see this in the Terminal
Serving HTTP on 0.0.0.0 port 8000 ...
Either way, open up your web browser and navigate to the following url:
http://localhost:8000
- You should see links to all the files in your folder. Click on the html file and your application should load. (Note, if you name your html file
index.html
, the application will load when you navigate tohttp://localhost:8000
Before you can run a local server on windows with python, you'll need follow a few steps.
-
You'll need a console application that lets you interact with Git and your computer in much the same way as the Terminal application on Apple computers. There are several options.
-
Install Git Bash
-
use all the default settings.
-
When you get to the
Adjusting your PATH environment
screen, be sure to choose the option forUse Git Bash Only
. -
You should have now have a program in your Start Menu called Git Bash. If you hit the Windows key to pull up the start menu and type “git bash” you should see the program highlighted.
-
You will now need to make sure that Git Bash recognizes python. You can do this temporarily with this command in Git Bash:
PATH=$PATH:/c/Python27/
(or whatever version of python you are running). However if you want this to be permanent you'll need to addc:\python27
to your system environment variablepath
. Here is how you access that.. -
An alternative to Git Bash is the windows built-in command prompt. This should work but you'll have to use DOS versions of the unix commands I'm showing in class.
-
An alternative to all of this is WAMPServer.
- Download WampServer from http://www.wampserver.com/en/.
- Install WampServer and follow instructions.
- The “www” directory will be automatically created (usually c:\wamp\www).
- Create a subdirectory in “www” and put your HTML/JS files inside.
- Open your internet browser and go to the URL : http://localhost/yourfile.html.
- Steve Klise
- Craig Protzel's Tutorial
- Setting Up A Web Server in Ch.4 of Interactive Data Visualization for the Web by Scott Murray
- ITP Creative JS