Sometimes you want to preview some web content locally on your Mac. Maybe you want to browse a backup of your home page or blog, or you want to run a local web application.
In previous versions of MacOS, you simply activated Personal Web Sharing in the control panel, and you could access the content of “Users/yourname/Sites” in the browser. This option is gone in the current MacOS. The web server however is still installed. You just need to know how to switch it on. :-)
- Open the Terminal.app and enter
Remember the response, this is your name that you need to replace in the path and the URLs below!
- Start the web server by entering the following command (it will ask for the admin password):
sudo apachectl start
- Open the Finder and copy your web content to “/Users/name/Sites/”. It’s okay to create subfolders under “Sites”.
- Open your web browser (by default, Safari) and browse to your local web URL (note the tilde):
You should see an index page or folder listing.
- To access a file such as “/Users/name/Sites/page.html”, or a directory such as “/Users/name/Sites/subfolder/”, the URLs look as follows:
If the webpage in question contains PHP files, they may show up as PHP code in the web browser instead of being executed. In this case, you need to activate PHP, too.
- Open the Terminal and edit the following configuration file.
sudo nano /etc/apache2/httpd.conf
- Search for lines that contain the word “PHP”. By default, they are commented out by a “#” character.
#LoadModule php5_module libexec/apache2/libphp5.so
- Remove the “#” character and save the file.
- Restart the web server.
sudo apachectl restart
- Reload the PHP page on your localhost in the web browser.
PHP is activated until you comment the line out again.