Skip to content

Local server

Lauren McCarthy edited this page Nov 13, 2013 · 63 revisions

Some functionality (loading external files, for example) works as expected when the files are placed online via FTP. However, if you try to view them locally, you see some kind of "cross-origin" errors in console. The solution to this is to view them using what's called a local web server. This tutorial includes instructions for setting this up on Mac OSX and Windows.

###Mac OS X

####Snow Leopard (10.6)

Snow Leopard has a built in web server, all you have to do is enable it and place the files in the right place.

  1. Go into Sys­tem Pref­er­ences > Shar­ing, and check the “Web Shar­ing” box.
  2. Place your project somewhere inside /Library/WebServer/Documents/.
  3. View it at http://localhost.

There's some further info here http://georgebutler.com/blog/setting-up-local-web-server-on-os-x-snow-leopard-10-6/.

####Lion (10.7) and Mountain Lion (10.8)

In Lion and Mountain Lion the enable web server option has been removed, but you can set it up manually.

  1. Open terminal.
  2. Type sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist. This turns on the server.
  3. Type:
mkdir ~/Sites

This creates the place your server will look for your files. 4. Type:

ls
``` Check whether you have a file like ```<your short user name>.conf```. 
5. If that file doesn't exist, you will need to create it with:

sudo vi /etc/apache2/users/.conf


Use the following as the content:
<Directory "/Users/<your short user name>/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
 
In vi, press <esc> and then ZZ to save and quit.

Lion has a built in web server, all you have to do is enable it and place the files in the right place.

1. Go into Sys­tem Pref­er­ences > Shar­ing, and check the “Web Shar­ing” box.
2. Place your project somewhere inside /Sites/.
3. View it at http://localhost/~username/.

There's some further info here https://discussions.apple.com/docs/DOC-3083.


####Mountain Lion (10.8)

3. Navigate to the Sites folder and place your project somewhere inside it.
3. View it at http://localhost/~username/.

There's some further info here https://discussions.apple.com/docs/DOC-3083.


####Windows

1. Download WampServer from [http://www.wampserver.com/en/](http://www.wampserver.com/en/).
2. Install WampServer and follow instructions.
3. The “www” directory will be automatically created (usually c:\wamp\www).
4. Create a subdirectory in “www” and put your HTML/JS files inside.
5. Open your internet browser and go to the URL : http://localhost/yourfile.html.
Clone this wiki locally