Jump to main content

Quick Note: Setting up a localhost on a Mac

  • Published:
  • Category: development

Many developers don’t even worry about setting up a localhost on their computers as automated task runners often will create one for you.

But at times I’ve found myself needing to run a localhost with no actual need to get a Gulp, Grunt or webpack setup going.

Sure, those times are far and few between these days, but the following commands can help you (or me for my own future reference) get a PHP or Python server up and locally running on your machine.

Setting up a local server

To successfully setup either a PHP or Python local server, you’ll need to use the command line to cd into the directory where you want to start up the server.


Once in the desired directory, run:
php -S localhost:2222

Now you can go to “localhost:2222” in your browser, and if you have an index.html or .php file in your root directory, you’re in business.

Pretty straight forward.


As with before, once in the desired directory, run:
python -m SimpleHTTPServer

Or specify a specific port number with the following:
python -m SimpleHTTPServer 8888