I need an http server to serve up static content on localhost.
It needs to meet the following conditions:
- easy to install, minimal configuration, just fire up from a directory and that's it
- supports OSX
- small memory footprint
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI need an http server to serve up static content on localhost.
It needs to meet the following conditions:
Apache is built into OSX an can easily be enabled.
See http://macdevcenter.com/pub/a/mac/2001/12/07/apache.html for some basic instructions.
You can use Python to run a simple http server. From the directory that you want to serve, run the following...
python -m SimpleHTTPServer
See this Linux Jornal article for more info.
python3 -m http.server
. stackoverflow.com/questions/7943751/…
You can use MAMP.
It comes with Apache, PHP and MySQL, and sets it all up with a few clicks. Note that you should never use MAMP in a production environment; PHP & MySQL settings are optimal for development but there are some security vulnerabilities.
A more current approach using Python3 (e.g. listening on localhost port 8080 and serving files form current directory):
python3 -m http.server --bind localhost 8080
Note: If you omit the --bind
argument it defaults to listen on ALL interfaces which is a security risk as anyone connected to your network can request files.
Or it's also possible using php
:
php -S localhost:8080
Python (and php) are not longer installed as part of the OS beyond MacOS 12.3, but they can be installed in a variety of other ways e.g using brew
).
See this question for approaches using netcat/bash.