Every Web developer needs to test files with a Web server and the most convenient way to do that is to run a Web server locally on your development machine and access it via localhost (127.0.0.1). One of the reasons Macs make such great dev machines for Web developers is they come standard with almost everything you need: Apache, MySql, Python, Perl, PHP, Java, etc.
From a Terminal window, these commands will start or stop Apache:
sudo apachectl start
sudo apachectl stop
After you’ve started Apache, browse to this address and you’ll see the standard Apache page:
http://localhost
The default location of the web site files on your file system is called the document root, and that is here:
/Library/WebServer/Documents
If you use this address:
http://localhost/~yourname
Those files are here:
/Users/yourname/Sites
Trouble shooting
If the default Apache page doesn’t load when you click http://localhost, check to make sure the Apache process loaded. You can type this into a terminal window to verify that Apache is loaded:
ps acx | grep -i 'httpd'
If you don’t see anything returned that means Apache failed to load. To find out why, run the Console app (you can find it in /Applications/Utilities or just type “console” into Spotlight). Click “All Messages” and you should see something like this:
httpd: Syntax error on line 117 of /private/etc/apache2/httpd.conf...
In that case just open the httpd.conf (you will probably need to “sudo vi httpd.conf”) and make adjustments. You may need to comment out some mods that are failing to load, or you need investigate what is wrong with the offending mod.