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)?
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)?
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:
terminal.php -S localhost:8080http://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.
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:
localhost:8888./Applications/MAMP/htdocs, any document you place in there will be accessible via localhost:8888. So if you adjust or add an index.html or index.php file, that will be the new main file you get when you go to localhost:8888.localhost:8888 is 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 localhost.Use your terminal, cd into your project folder then type:
npx http-server
That should start up a server for you and will be available on: http://127.0.0.1:8080 or follow the instructions on your terminal.
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.