Setting up your Mac as a server for testing Web pages

by Joe Gillespie — Jul 1, 2004

Setting up your OS X Mac as a local server for testing your Web pages could hardly be easier. Apache comes already installed, all you have to do is go into the Sharing control panel, check Personal Web Sharing and click on the Start button.

At the bottom of the window, you will see something like...

View this computer's website at http://10.0.1.3 or your personal website at http://10.0.1.3/~<username>/

If you click on either of those links, you should see the default Web pages.

The actual location of those sites is not so obvious but if you look in /Library/WebServer/ you will find two folders – CGI-Executables and Documents. The Documents folder is your computer's 'home directory'. It will be stuffed with default files in many languages which you can leave or move off somewhere else if you like.

If you put a new 'index.html' file in here, it will show up when you go to http://10.0.1.3 (or whatever the control panel tells you the address is). This address will change because it is dynamically allocated so it's probably better to use (and bookmark)...

http://<computer name>.local/index.html

The computer name is given at the top of the Sharing control panel.

Now, chances are, that all your Web files are somewhere else on your hard disk, or on a different disk altogether. You would think that putting an alias to your site folder into the Library/WebServer/Documents folder would give you access to them but unfortunately, Mac style aliases don't work in this UNIX environment. You can't just drag an alias to a folder into the Web but you can set up a UNIX alias, called a 'symbolic link' to do the same thing.

Open the Terminal application in your Utilities folder.

You will see the default command line prompt:-

[<computer name>:~]<username>

Type, or copy and paste this:-

cd /Library/Webserver/Documents/

and hit return.

cd means change directory, so you will now be pointing at the Documents folder. To check that you are, type this:-

ls

which means list the contents of the current directory

To set up the symbolic link in the Documents folder, type...

ln -s<path to your site folder><aliasname>

For example, if you keep your personal site files inside a folder called MySite at the top level on your hard disk...

ln -s /MySite mysite

Note the space separating the path from the alias name.

Now, in your browser, enter the URL

http://<computername>.local/mysite/index.html

and you should see the home page of your MySite folder.

If, as I do, you keep your site files on a separate hard disk, the path syntax is slightly different...

ln -s /Volumes/<drivename>/MySite mysite

That is how to make a symbolic link to a folder on an external drive.

Now, you can test how your site behaves on a 'real' server – very useful for checking if you have filename case sensitivity problems or broken links.

If you have other Macs or PCs on a local network, they can access the same URL, so you can check your pages in other browsers too.

Del.icio.us Digg Technorati Blinklist Furl reddit Design Float