I have a page that I need to serve on
localhost for the fonts to appear properly.
What is the easiest way to do this (on a Mac)?
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 community
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:
php -S localhost:8080
http://localhost:8080in 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.
There are a lot of different ways to do this in Mac OS X. But to me, the simplest way—conceptually and visually—is via a graphical user interface like what MAMP offers. The non-Pro version of MAMP is 100% free and works great for basic usage like this:
MAMP installs a local server environment in a matter of seconds on your Mac OS X computer, be it MacBook or iMac. Like similar packages from the Windows- and Linux-world, MAMP comes free of charge, and is easily installed. MAMP will not compromise any existing Apache installation already running on your system. You can install Apache, PHP and MySQL without starting a script or having to change any configuration files! Furthermore, if MAMP is no longer needed, just delete the MAMP folder and everything returns to its original state (i.e. MAMP does not modify any of the "normal" system).
So basically you just download MAMP and it is installed like any other application, but it will allow you to create a Mac equivalent of a LAMP stack (Linux Apache MySQL PHP) on your desktop. And if all you want to do is serve a simple page via
localhost, just do this:
/Applications/MAMP/htdocs, any document you place in there will be accessible via
localhost:8888. So if you adjust or add an
index.phpfile, that will be the new main file you get when you go to
localhost:8888is a bit obscure a URL for you to use, then just open up MAMP’s preferences and set the ports to the default Apache/MySQL ports of 80 and 3306. You will need to enter your administrator password to change the ports to these more standard ports, but after that is done, you can reach the content directly via
Someone looking for "the easiest" solution probably wants to use a GUI rather than the command line. Older versions of OS X had a checkbox in the Sharing Preference Pane that enabled the web server. You can replicate that functionality with the freeware https://clickontyler.com/web-sharing/
The free Anvil App is how I do this. It integrates with Hammer.app to display pre-processed sites, but you can also just add a static site folder. Sites can be accessed via a .dev site extension, which the browser sees properly to load external fonts, code, etc.