I’m not an IT guy.
So when I decided I wanted to setup my Mac’s built-in Apache server to serve up goodness on the web straight from my home office, I went looking for info on how to remap ports to get my “sites” folder visible from outside my home network — from the Internet.
I had a hell of a time finding the right information on the web, and I’m going to have to redo this when I move in the fall, so I thought I’d post the information here for myself and for any other person looking to serve information through the web from his or her Mac.
Background: Your router uses the public IP address your machine is given by your Internet provider. It hands out different IP addresses to all the machines on that network. Usually these look something like 10.0.1.2, or 172.16.1.2, or 192.168.1.2. If you try to access that IP address from the Internet, it won’t work–that’s an internal address only, sort of like your home’s little intranet. To get access to your built-in Apache folders, we need to redirect the incoming requests to the appropriate machine. We have to trick the router.
It’s actually pretty simple. Assuming you’re using an Airport Express, Airport Extreme, or Time Machine (because why wouldn’t you?), here’s what you do:
Open Airport Utility. (An easy way to find it is to hold Command and hit the spacebar, then do a Spotlight search for Airport Utility.) Once it has found your Apple wireless device, select Manual Setup.
First we need to force the router to give the machine you want to serve the data an IP address ending with a digit higher than 200. I don’t know the technical reason for this (I’m not an IT guy), but I know that we need to do it. Select Internet on the top row of icons. Next, click the DHCP button right under the row of icons. Change the last digits of the DHCP ending address to 200, for example 10.0.1.200.
Now select Advanced on the top row of icons. Just below that area, select Port Mapping.
Now you’ll see this:
Click the plus sign at the lower left of the “Allow” box to start adding values.
What you’re doing here is re-routing certain specific requests for data. As an example, let’s start with Apache. To serve web data from your Mac to the Internet, you have to get out from behind your router’s IP address. Requests for web data come in on port 80. In the Port Mapping Assistant window, (the one that comes up when you click the plus sign), enter 80 for all the UDP and TCP Ports. That leaves only the Private IP address field blank. Here, enter the IP address the router has given your machine. Don’t know it? No problem.
Open System Preferences (use the aforementioned Spotlight method or the Apple menu in the upper left corner of your screen), and click Sharing. You will see a list of sharing services. The one we need to look at is Web Sharing, so click that. Now you will see Web Sharing: On. If you don’t see that, turn it on. Your “Sites” folder isn’t accessible unless this is on. Once it’s on, it will display the following message:
Web Sharing allows users of other computers to view web pages in the Sites folders on this computer.
Your computer’s website:
some numeric URL, like http://10.0.1.200Your personal website:
That same numeric URL appended with with your username, like http://10.0.1.200/~yourname
* NOTE: What’s the difference between these URLs? The first one refers to the location Library/WebServer/Documents and the second refers to your Sites folder, found at /~yourname/Sites (where “yourname” is the user name for the active account), so technically you have two built-in webserver folders.
Enter the IP address of the location you want to serve data to the web from (whichever folder you want to use) in the Private IP address field in the Airport Utility. Now that you have port 80 mapped to this destination, you can surf to the IP address your ISP gave you and you will be forwarded to that folder. You can now buy a domain name and forward it to that IP address, for a truly professional look. No one would ever even know they’re browsing documents on your machine–at your home.
The Mac’s built-in web serving capabilities also include PHP support, but you may need to turn PHP on.
Some good things about serving data from your Mac to the ‘Net are:
As a final note, iChat may act up after you make this change. To fix it, you need to add more “Allow” instances in Airport Utility. Using the same IP address information, create one entry for each of the following ports:
16393 through 16402 (yes, one for each number between 16393 and 16402 — ten values total)
5060
5190
5297
5298, and
5678
So you should have 16 entries in all when you’re done.
I think that’s it. Let me know if you run into problems.
Next up: Setting up and managing MySQL on your Mac. I’ll show you how you can create and manage databases for your sites right from your Mac with the free, open-source MySQL package.
