Sunday, October 4, 2020

How to set up a Web Server on macOS


▶ Method 1 (with a single Terminal command)

 

Start a Simple Web Server from Any Directory with a Terminal command

You need only one CLI command to start a Web Server on macOS. Just change the directory you want to use and run the following command. This is the fastest way to run a Web Server without additional configurations.

▷ With Python 2
python -m SimpleHTTPServer
(default port will be running with 8000)

MBPr:/Users/analysisman/Downloads% python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

# Client 192.168.68.3 accessed the web server
192.168.68.3 - - [16/Oct/2020 00:20:12] code 400, message Bad request syntax ("\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03w\xc7\xbd\x04'R\x01\x96'\x01\xd9\x06\x95\xab^\xd4\xc0>\x91\x13p\xbcn\x1d\xf1\x96O\x8e")
192.168.68.3 - - [16/Oct/2020 00:20:23] "GET / HTTP/1.1" 200 -
192.168.68.3 - - [16/Oct/2020 00:20:23] code 404, message File not found
192.168.68.3 - - [16/Oct/2020 00:20:23] "GET /favicon.ico HTTP/1.1" 404 -


▷ With Python 3
python3 -m http.server --cgi 8080


▶ Method 2 (with Apache server)

 

The following guide is required more settings and runs the Apache server, PHP, and Perl module. The instruction is slightly different for each version of macOS.

Setting up a local web server on macOS 10.15 “Catalina”
Setting up a local web server on macOS 10.14 “Mojave”
Setting up a local web server on macOS 10.13 "High Sierra"
Setting up a local web server on macOS 10.12 "Sierra"
Setting up a local web server on OS X 10.11 "El Capitan"
Setting up a local web server on OS X 10.10 "Yosemite"
Setting up a local web server on OS X 10.9 "Mavericks"
Setting up a local web server on OS X 10.8 "Mountain Lion"
Setting up a local web server on MacOS X 10.7 "Lion"
Setting up a local web server on MacOS X 10.6 "Snow Leopard"


No comments: