Skip to content

Commit 5cca639

Browse files
committed
added web_servers.md
1 parent 27749cb commit 5cca639

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

web-servers.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
2+
3+
[Discussion on reddit](http://www.reddit.com/r/webdev/comments/1fs45z/list_of_ad_hoc_http_server_oneliners/).
4+
5+
### Python 2.x
6+
7+
```shell
8+
$ python -m SimpleHTTPServer 8000
9+
```
10+
11+
### Python 3.x
12+
13+
```shell
14+
$ python -m http.server 8000
15+
```
16+
17+
### Twisted <sub><sup>(Python)</sup></sub>
18+
19+
```shell
20+
$ twistd -n web -p 8000 --path .
21+
```
22+
23+
Or:
24+
25+
```shell
26+
$ python -c 'from twisted.web.server import Site; from twisted.web.static import File; from twisted.internet import reactor; reactor.listenTCP(8000, Site(File("."))); reactor.run()'
27+
```
28+
29+
Depends on [Twisted](http://twistedmatrix.com/trac/wiki/Downloads).
30+
31+
### Ruby
32+
33+
```shell
34+
$ ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start'
35+
```
36+
37+
Credit: [Barking Iguana](http://barkingiguana.com/2010/04/11/a-one-line-web-server-in-ruby/)
38+
39+
### Ruby 1.9.2+
40+
41+
```shell
42+
$ ruby -run -ehttpd . -p8000
43+
```
44+
45+
Credit: [nobu](https://gist.github.com/willurd/5720255#comment-855952)
46+
47+
### adsf <sub><sup>(Ruby)</sup></sub>
48+
49+
```shell
50+
$ gem install adsf # install dependency
51+
$ adsf -p 8000
52+
```
53+
54+
Credit: [twome](https://gist.github.com/willurd/5720255/#comment-841393)
55+
56+
*No directory listings.*
57+
58+
### Sinatra <sub><sup>(Ruby)</sup></sub>
59+
60+
```shell
61+
$ gem install sinatra # install dependency
62+
$ ruby -rsinatra -e'set :public_folder, "."; set :port, 8000'
63+
```
64+
65+
*No directory listings.*
66+
67+
### Perl
68+
69+
```shell
70+
$ cpan HTTP::Server::Brick # install dependency
71+
$ perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>8000); $s->mount("/"=>{path=>"."}); $s->start'
72+
```
73+
74+
Credit: [Anonymous Monk](http://www.perlmonks.org/?node_id=865239)
75+
76+
### Plack <sub><sup>(Perl)</sup></sub>
77+
78+
```shell
79+
$ cpan Plack # install dependency
80+
$ plackup -MPlack::App::Directory -e 'Plack::App::Directory->new(root=>".");' -p 8000
81+
```
82+
83+
Credit: [miyagawa](http://advent.plackperl.org/2009/12/day-5-run-a-static-file-web-server-with-plack.html)
84+
85+
### Mojolicious <sub><sup>(Perl)</sup></sub>
86+
87+
```shell
88+
$ cpan Mojolicious::Lite # install dependency
89+
$ perl -MMojolicious::Lite -MCwd -e 'app->static->paths->[0]=getcwd; app->start' daemon -l http://*:8000
90+
```
91+
92+
*No directory listings.*
93+
94+
### http-server <sub><sup>(Node.js)</sup></sub>
95+
96+
```shell
97+
$ npm install -g http-server # install dependency
98+
$ http-server -p 8000
99+
```
100+
101+
*Note: This server does funky things with relative paths. For example, if you have a file `/tests/index.html`, it will load `index.html` if you go to `/test`, but will treat relative paths as if they were coming from `/`.*
102+
103+
### node-static <sub><sup>(Node.js)</sup></sub>
104+
105+
```shell
106+
$ npm install -g node-static # install dependency
107+
$ static -p 8000
108+
```
109+
110+
*No directory listings.*
111+
112+
### PHP <sub><sup>(>= 5.4)</sup></sub>
113+
114+
```shell
115+
$ php -S 127.0.0.1:8000
116+
```
117+
118+
Credit: [/u/prawnsalad](http://www.reddit.com/r/webdev/comments/1fs45z/list_of_ad_hoc_http_server_oneliners/cad9ew3) and [MattLicense](https://gist.github.com/willurd/5720255#comment-841131)
119+
120+
*No directory listings.*
121+
122+
### Erlang
123+
124+
```shell
125+
$ erl -s inets -eval 'inets:start(httpd,[{server_name,"NAME"},{document_root, "."},{server_root, "."},{port, 8000},{mime_types,[{"html","text/html"},{"htm","text/html"},{"js","text/javascript"},{"css","text/css"},{"gif","image/gif"},{"jpg","image/jpeg"},{"jpeg","image/jpeg"},{"png","image/png"}]}]).'
126+
```
127+
128+
Credit: [nivertech](https://gist.github.com/willurd/5720255/#comment-841166) (with the addition of some basic mime types)
129+
130+
*No directory listings.*
131+
132+
### busybox httpd
133+
134+
```shell
135+
$ busybox httpd -f -p 8000
136+
```
137+
138+
Credit: [lvm](https://gist.github.com/willurd/5720255#comment-841915)
139+
140+
### webfs
141+
142+
```shell
143+
$ webfsd -F -p 8000
144+
```
145+
146+
Depends on [webfs](http://linux.bytesex.org/misc/webfs.html).
147+
148+
### IIS Express
149+
150+
```shell
151+
C:\> "C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:C:\MyWeb /port:8000
152+
```
153+
154+
Depends on [IIS Express](http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-express-overview).
155+
156+
Credit: [/u/fjantomen](http://www.reddit.com/r/webdev/comments/1fs45z/list_of_ad_hoc_http_server_oneliners/cada8no)
157+
158+
*No directory listings. `/path` must be an absolute path.*
159+
160+
# Meta
161+
162+
If you have any suggestions, drop them in the comments below or on the reddit discussion. To get on this list, a solution must:
163+
164+
1. serve static files using your current directory (or a specified directory) as the server root,
165+
2. be able to be run with a single, one line command (dependencies are fine if they're a one-time thing),
166+
3. serve basic file types (html, css, js, images) with proper mime types,
167+
4. require no configuration (from files or otherwise) beyond the command itself (no framework-specific servers, etc)
168+
5. must run, or have a mode where it can run, in the foreground (i.e. no daemons)

0 commit comments

Comments
 (0)