Serve local web pages via name not IP number

29.11.2008

Replace mysites with whatever name you've chosen for your server, and then save the file and quit the editor (press Control-X to exit, Y to save your changes, and then Return to accept the filename if you're using nano).

Set up Apache

Now that you've named your server, you need to tell Apache how to convert mysites into the IP address of your Mac, so that it can display your web pages. The file you need to modify can be found in /etc/apache2/users, so cd there as a first step: cd /etc/apache2/users. In this folder, you'll find a ".conf" file for each user on your Mac. You want to edit the file for your user, again with root privileges; type sudo nano username.conf (where username is your short username) and enter your password when prompted. Move the cursor to the bottom of the file, and add these lines:

Replace username with your user's short username, and change mysites to the server name you used when editing the hosts file. Save the file and quit the editor.

If you also need access to sites in the standard /Library -> WebServer -> Documents folder, you need to edit one additional file. First, move into the right directory with cd /etc/apache2/extra, and then edit the httpd-vhosts.conf file (again, using sudo). Add these lines at the end: