The easiest way to serve a page to localhost on OS X
Since OS X comes with python2 I suggest:
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
As of PHP 5.4.0, the CLI SAPI provides a built-in web server. More details in the official PHP documentation:
- Open
terminal
. - Navigate to the folder (directory) containing the file you want to serve.
php -S localhost:8080
- Go to
http://localhost:8080
in the browser.
In older versions of OS X, there was a Preference Pane (System Preferences → Sharing → Web Sharing) that allowed you to easily enable the built-in Apache web server. Once enabled, all you had to do was place the file to be served in a directory named Sites
inside your home directory, and then you could fetch http://localhost/~yourusername/filename.html.
Sadly, the Preference Pane was removed in OS X 10.8. You can either install a replacement for it or activate it using a shell command.