Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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!

@vaibhavjindal
Copy link

vaibhavjindal commented May 7, 2018

Thanks!
Just what i needed.

@tarekahf
Copy link

tarekahf commented May 10, 2018

That was fantastically easy .... thank you so much, I use NPM Server and it is way better than the complicated Eclipse and Tomcat setup.

@AllieCR
Copy link

AllieCR commented May 22, 2018

Thank you! Exactly what I needed for testing out ES2015 import/export

@octoxalis
Copy link

octoxalis commented Aug 9, 2018

Well, nice simple guide deserving congrats!
I just tested both the npm and python approaches: so cool to quickly be "online" to test something.

@JamesSwift
Copy link

JamesSwift commented Sep 13, 2018

A very useful tutorial. If you want to easily set up a web server on ubuntu, you might find my scripts helpful: https://github.com/JamesSwift/SharedServerTools

@byteknacker
Copy link

byteknacker commented Oct 23, 2018

This article is amazing! I can now start a web server without writing any additional code. Thank you so much!

@saurav-bhagat
Copy link

saurav-bhagat commented Nov 30, 2018

What is the exact need of setting up a local server for serving static files? Like why this way is preferable?

@iarickvigasi
Copy link

iarickvigasi commented Feb 1, 2019

Hey, I've created simple and beautifully looked solution for those who are not familiar with the console.

Check out https://github.com/iarickvigasi/NUIS

@arneper
Copy link

arneper commented Apr 14, 2019

super simple and easy to follow. Thanks.

@proffessionalshivam4444

superb explanation thnx

@kristynagel
Copy link

kristynagel commented Jun 19, 2019

Thank you! I have no idea what this Node.JS stuff is, I'm just running it because it's mentioned in the Zero to Mastery Web Dev (Udemy) course that we'll be learning it. :)

@75lb
Copy link

75lb commented Jun 19, 2019

http-server has not been updated since Jan 2018, local-web-server is an excellent alternative.

@wangdagithub
Copy link

wangdagithub commented Jun 23, 2019

can IIS(windows server 2012) create non-localhost website in virtual box ? like www.practice.com with IP address 217.21.23.1 something like this ? if yes ,then how can i access the website from Host system . i am a new guy on IIS and virtual box. i want to create a public website using IIS in server 2012 and visit that site from my Host system(Ubuntu), can anyone guide me how to achieve this ? my virtual box network is bridged type. thanks in advance

@bossblackx
Copy link

bossblackx commented Sep 4, 2019

thank you so much its work ! :D

@azazqadir
Copy link

azazqadir commented Sep 5, 2019

I have been using Apache for my apps on Mac for so long. Since it comes preinstalled i don't even remember how to configure Apache manually. For servers, I have been using platforms for Apache hosting where servers comes preinstalled with it. This guide was a nice reminder of how to do it manually.

@ChachyDev
Copy link

ChachyDev commented Oct 19, 2019

I'm using Mac but I have to say it doesn't work for me. I don't see any ‘Sites’ folder in username and nor setting a html file make my localhost show anything

juse use node

@ovicrisan
Copy link

ovicrisan commented Nov 1, 2019

You can also do it with PHP, see https://www.php.net/manual/en/features.commandline.webserver.php :

php -S localhost:8000

@supernin
Copy link

supernin commented Dec 1, 2019

I have a web page built LAMP installed what next? How do I get the page from localhost to server?

@Andreluizfc
Copy link

Andreluizfc commented Dec 10, 2019

Thank you!

@NickBaynham
Copy link

NickBaynham commented Jan 5, 2020

This is awesome! I used it to make available some static demo HTML for use in Selenium-Webdriver examples.

@mgalmes
Copy link

mgalmes commented Feb 18, 2020

For NodeJS I simply used: npx http-server

@gjmkoper
Copy link

gjmkoper commented Feb 29, 2020

The link for Windows refers to a web page that will no longer be maintained. For W10 I found suitable instructions here.

@sajidmanzar
Copy link

sajidmanzar commented Mar 2, 2020

Thank you for this valuable information. Previously I installed XAMPP and then Anaconda navigator and Jupyter notebook stopped working showing error. I searched on google, most of the answers were to uninstall and re-install. I did it various times. Then I realized because Jupyter notebook is also running on the webserver on localhost:8888 so it may be clashing. I uninstalled xampp, removed the folder completely and re-installed Anaconda. Bingo, its started working.

@michjnich
Copy link

michjnich commented Mar 23, 2020

SimpleHTTPServer is the old solution. With modern python modules have been moved around and you need to use

python -m http.server 8000

@attacomsian
Copy link

attacomsian commented Mar 27, 2020

Anyone who is looking for PHP local web server for quick testing, just use the following command (required PHP 5.4.x and higher):

$ php -S localhost:8080

I wrote an article on this topic that explains all these options.

@HeinThuta
Copy link

HeinThuta commented Apr 21, 2020

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.

@NickBaynham
Copy link

NickBaynham commented Apr 21, 2020

@HeinThuta
Copy link

HeinThuta commented Apr 21, 2020

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

@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

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