Skip to content

Instantly share code, notes, and snippets.

@jgravois
Last active August 1, 2024 19:39
Show Gist options
  • Save jgravois/5e73b56fa7756fd00b89 to your computer and use it in GitHub Desktop.
Save jgravois/5e73b56fa7756fd00b89 to your computer and use it in GitHub Desktop.
a simple guide for getting a local web server set up

Do I have a web server running?


having a web server turned on doesn't necessarily mean you are serving pages on the world wide web. its what allows you to load your own static files (.html, .js etc.) in a browser via http://.

if you're not sure whether or not you have a web server running, no problem! its easy to confirm.

what happens when you visit http://localhost/?

if you're looking at a webpage, great!
you're done.

What if i don't?

Windows

the most popular web server software for microsoft computers is IIS. if its not already running, you can follow the instructions below to get things set up.

https://msdn.microsoft.com/en-us/library/ms181052(v=vs.80).aspx

iis screenshot

afterward, save a .html file in C:/inetpub/wwwroot and try to access it via http://localhost/[myfile].html. if the page is served up, you're ready to roll.

Mac

Apache comes preinstalled on Apple computers. If its not running, you can follow the instructions below to get it turned on.

http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/

afterward, save a .html file in ~/Users/[yourlogin]/Sites/ and try to access it via http://localhost/~[yourlogin]/myfile.html. if you can view the content, all is well.


🎵 interlude 🎵


What if I'd rather use something else?

you don't need a why, but here are a couple reasons:

  • you don't have admin privileges on the computer
  • you think Apache .conf files are scary, and editing text in VIM is even more frightening
  • you want something lightweight

SimpleHTTPServer (a Pythonic approach)

Python comes preinstalled on Macs (and is installed on Windows with ArcGIS Software) so it's SimpleHTTPServer module is an excellent choice.

  1. navigate into the folder where you plan on saving your .html files (using terminal/cmd) and execute the following command:

    python -m SimpleHTTPServer 1337

    if you're using Python 3.x or higher, you'd use

    python -m http.server 1337
  2. now you should be able to access your own files via http://localhost:1337/myfile.html in Chrome, Firefox or any other web browser.

<html>
  <body>
    <h1>i'm web serving!</h1>
  </body>
</html>

hello world

http-server (for Node)

Node.js gets more popular by the day, so if you already have it installed (or don't mind taking two minutes to do it now) the npm module http-server is a really good choice too.

using http-server

  1. if you haven't already installed Node.js, visit the site below and lay it down

https://nodejs.org/en/download/

  1. next, open terminal or cmd and install the http-server module globally on your machine
npm install http-server -g
  1. run it using CLI (specifying the folder you'd like to serve files from)
http-server ./[yourfolder] -p 1337
  1. now you should be able to access your files (via something like http://localhost:1337/myfile.html) in a web browser.

thats it!

@HeinThuta
Copy link

Remove the local host part

On Tue, Apr 21, 2020 at 11:03 AM HeinThuta @.***> wrote: @HeinThuta commented on this gist. ------------------------------ Can I access local server hosted by python with other devices in the same local network? I can't access http://192.168.1.101/localhost:8000/ from my mobile. The first way with IIS is ok and greatly thankful. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/5e73b56fa7756fd00b89#gistcomment-3263330, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF7L5TZWUBOKNY7P2YQTFGLRNWYSHANCNFSM4HHI6AEA .

I have tried these : http://192.168.1.101/localhost:8000/Home.html , http://192.168.1.101:8000/Home.html , http://192.168.1.101:80/Home.html , http://192.168.1.101:80/localhost:8000/Home.html But nothing changes.

@NickBaynham
Copy link

NickBaynham commented Apr 21, 2020 via email

@HeinThuta
Copy link

HeinThuta commented Apr 21, 2020

When you start it up you have to identify the network ip instead of local host - that only works if you are planning to connect from the same machine

On Tue, Apr 21, 2020 at 11:26 AM HeinThuta @.> wrote: @HeinThuta commented on this gist. ------------------------------ Remove the local host part … <#m_795133586786139166_> On Tue, Apr 21, 2020 at 11:03 AM HeinThuta @.> wrote: @HeinThuta https://github.com/HeinThuta commented on this gist. ------------------------------ Can I access local server hosted by python with other devices in the same local network? I can't access http://192.168.1.101/localhost:8000/ from my mobile. The first way with IIS is ok and greatly thankful. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/5e73b56fa7756fd00b89#gistcomment-3263330, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF7L5TZWUBOKNY7P2YQTFGLRNWYSHANCNFSM4HHI6AEA . I have tried these : http://192.168.1.101/localhost:8000/Home.html , http://192.168.1.101:8000/Home.html , http://192.168.1.101:80/Home.html , http://192.168.1.101:80/localhost:8000/Home.html But nothing changes. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/5e73b56fa7756fd00b89#gistcomment-3263364, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF7L5TYFSMF7H3QJYWM4WFDRNW3K3ANCNFSM4HHI6AEA .

I can connect the website from the hosting PC. So I can't access from other devices like hosting with IIS? I started studying networking recently and I have to learn a lots. So please don't mind if my questions disturb you. Thanks

@clrsky
Copy link

clrsky commented Aug 1, 2024

thank you , this helped me setup my server in minutes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment