Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to host html [duplicate]

Tags:

html

hosting

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.

like image 490
Steven Morad Avatar asked Feb 10 '26 23:02

Steven Morad


2 Answers

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
like image 52
Mark Setchell Avatar answered Feb 13 '26 17:02

Mark Setchell


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.

like image 22
Stefano Sanfilippo Avatar answered Feb 13 '26 16:02

Stefano Sanfilippo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!