2

What is the simplest way to host an HTML page over LAN?

I literally just need to have like 5 lines of HTML, so I don't want to download and setup an Apache server. I just want to know the fastest/simplest way to do this on Windows, or I can also use one of my Linux virtual machines if it's faster.

Steven Morad
  • 2,511
  • 3
  • 19
  • 25
  • 1
    Be more precise about your needs. For instance, are you setting up a testing server or is it for actually serving a website? At home, at work? How many users expected? – Stefano Sanfilippo Jan 23 '14 at 22:55
  • Just testing, so one user. – Steven Morad Jan 23 '14 at 22:56
  • 1
    http://stackoverflow.com/questions/5050851/best-lightweight-web-server-only-static-content-for-windows contains some pointers to lightweight Windows http servers – fvu Jan 23 '14 at 22:57

4 Answers4

3

Use netcat, or nc:

:top
nc -l -p 80 -q 1 < index.html
goto top

It's a simple binary without any installation. It doesn't do CGI or PHP or anything, but it can sure dish up 5 lines of HTML.

Actually, if you use the "k" (keep-alive) option you can remove the loop, and make it simpler:

nc -kl 80 < index.html
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
2

Since you need a web server for testing and no heavy concurrent use is expected, I'll just keep it simple.

Please note that both solutions are very simple but not very secure, use them for development purposes but don't rely on neither of them for anything barely similar to a stable (people would say "production") server.

Navigate to the directory where your HTML file is located using cmd.exe, then issue:

Using Python

# python 3
python -m http.server
# python 2
python -m SimpleHTTPServer

A HTTP server will be started on port 8000. It will serve the current directory.

Should you need a different port, just specify it:

# python 3
python -m http.server 8080
# python 2
python -m SimpleHTTPServer 8080

http.server is part of the "batteries included": you will not need to install any extra package, apart from the Python interpreter, of course.

Python comes already installed on most Linux distributions, so switching to Linux might be simpler than installing Python on Windows, although that boils down to downloading and running an installer.

Using PHP 5.4 or above

php -S 0.0.0.0:8080

This will also process PHP scripts, but HTML resources will be served fine.

Aidin
  • 1,271
  • 14
  • 20
Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • 1
    assuming that he has python installed – Pedro Lobito Jan 23 '14 at 22:59
  • @Tuga at the end of the day, he/she will have to install something in order to achieve his/her goal. – Stefano Sanfilippo Jan 23 '14 at 23:07
  • I agree, but it's way simpler to copy and paste 1 mongoose file than installing all the python files for such a simple task. – Pedro Lobito Jan 23 '14 at 23:10
  • Is there any way to drop the port number from the URL? Would I just have to make the default port 80? – Steven Morad Jan 23 '14 at 23:31
  • Yes, but you will need to run it with high priviliges (`sudo` on Linux) to use ports under 1024, for security reasons. Like, `sudo python -m SimpleHTTPServer 80`. I will reiterate that you should use it only for development, since SimpleHTTPServer is, you guess, _simple_. It has no intentional flaw or backdoor, but it's not developed with security in mind. – Stefano Sanfilippo Jan 23 '14 at 23:36
  • 1
    use `python -m SimpleHTTPServer 80` , then navigate to `http://localhost/yourfile.html` – Pedro Lobito Jan 23 '14 at 23:37
  • Also note that by running on Linux with `sudo`, you expose your machine to potential vulnerabilities. If you run the server inside a Linux VM, this will not be a vital issue, but be careful and don't say I didn't warn you :) Real world servers (like Apache) start as root, bind to port 80 then immediately drop from high priviliged user to "normal" user. – Stefano Sanfilippo Jan 23 '14 at 23:45
  • In the latest release of python it should be python3 -m http.server – Tertius Geldenhuys Sep 10 '22 at 00:10
1

http://www.lighttpd.net/ is pretty light weight and easy to get running.

chasepeeler
  • 137
  • 8
1

I recently used mongoose for a similar purpose. It supports Windows. From the homepage:

Mongoose executable does not depend on any external library or configuration. If it is copied to any directory and executed, it starts to serve that directory on port 8080. If some additional config is required - for example, different listening port or IP-based access control, then a mongoose.conf file with respective options (see example) can be created in the same directory where executable lives. This makes Mongoose perfect for all sorts of demos, quick tests, file sharing, and Web programming.

Download the windows exe (no need to install) from here , save it on the folder where your html file is and execute it. Check the image below to know how to start the server:

enter image description here

After selecting Start Browser on Port 8080 your browser will open automatically displaying the contents of the folder.

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268