Monday, February 4, 2008

How to Host Your Own Website

I'm hosting three websites from my dining room, and it costs me zilch. Each website loads quickly (because there's not much traffic), there is no website size or data transfer limit, the only fee is my monthly broadband subscription and electricity, and I've never (yet) had a site crash (that wasn't my own dumb fault). Though I haven't bought URLs for my sites, I could and they would appear to the outside world to be functionally identical to any website you might use any day. It takes a little software tweaking to get set up, but once you've planted your little plot of server farm, it will seem to run itself. Before you invest the time, you may want to read the caveats at the bottom of this post.

Hardware You'll Need

1. Broadband connection
2. A computer you're willing to leave on pretty much all the time
3. That's it!

Hardware That's Nice to Have

1. A wired router that uses NAT will make your server more secure. If you're using more than one computer, you'll need a router that allows port forwarding. Both NAT and port forwarding are common features available on most routers. IP reservation is a helpful router feature as well.
2. If you're using a second computer as your web server, it's nice to have an extra keyboard, mouse, and a monitor that allows more than one video source. Newegg.com has cheap keyboards/mouses. Many flatscreen LCD monitors have a digital and an analog input and a "video source" button. You could also get a video signal switch that allows your monitor to switch between two different computers. Try RadioShack.

Software You'll Need

1. Apache HTTP Server This is a free software program that allows your computer to host a website.
2. Free dynamic DNS and URL redirection software from No-IP.com or DynDNS.com.
3. That's it!

Hardware Setup

1. Single computer as personal computer and webserver: no additional setup needed. Basically, if you can access the internet using a broadband connection, you're ready to move on to the software setup. I strongly urge that you use a wired router with the specs mentioned above in "Hardware That's Nice to Have". You're much safer from hackers if you have a wired, NAT router between your computeryou're your cable modem/DSL.
2. Two computer setup where one is your personal computer and the other is your webserver: Leave your PC connected as usual. Set up your webserver as you would a normal PC. Connect your ethernet card to your router. That's it!

Software Setup

The Dynamic IP Problem

1. Your IP address is like your computer's street address on the internet. Most ISPs change their consumer accounts IP addresses periodically, so that hackers can't "stake out your house" over the summer to see if you're on vacation (digitally, of course) and then steal your buried treasure, gold bars, and family jewels. But what if you want people to be able to find your house (and therefore your website)?
2. The all-knowing world wide web has developed a clever fix for this problem: dynamic IP URL forwarding. Dynamic DNS services like No-IP.com and DynDNS.com give you permanent URL on their server and a safe piece of software that checks your IP address every few minutes. If your IP address changes, No-IP reports back to No-IP.com's servers with your new IP address and No-IP.com's server sends web traffic from your URL to your new IP. Clever! And 100% free of charge!
3. Go now to No-IP.com, register for a free account, and download the software. Make sure to give No-IP.com an email address you check periodically - they will email you to renew your free account and cancel after 90 days if you don't renew (renewing is easy).
4. Install No-IP on the computer you want to be your webserver. Login to the software you just installed. Make sure to set it up so that the No-IP software starts automatically every time you turn on your computer. Reboot the server computer and confirm that No-IP begins running on startup. Okay, you're half done with the No-IP setup. More on this in a few minutes.

Webserver software

5. Of course, you can't just "have a website" on your computer. You need some software that can accept and understand the language of the world wide web. Go download the Apache HTTP Server software. The Apache website can be confusing - I recommend not trying to read too much of it. However, make sure you join the "
Apache Server Announcements" newsletter so you know when it's time to upgrade to Apache's latest "stable version". If you don't update regularly, you run the risk of opening your webserver to hacker attack. For now, download whatever version of the software they say is the "best version available" for your OS. If you're using Windows, you'll likely want the "Windows binary" option. Install the software on the computer you want to be your webserver. If offered openSSL encryption, you can say "no thanks" since this is intended for ecommerce sites. Honestly, I remember finding this installation step a little confusing, and I don't remember how to do it. One thing that you should know is that, depending on your OS, you may have to start up the Apache webserver software every time you reboot your server computer. Fortunately, you'll leave your server on most of the time and won't have to reboot often.
6. Reboot the server computer, then open the Apache HTTP Server software and fire it up. Be aware that the default settings for Apache upon install will work fine to host your website, but there are many ways to customize how your computer will host web traffic using Apache. If you like, you can check out those options in the Apache Configuration File, but be careful about making changes to it - I recommend having a backup copy before editing the configuration.
7. Okay, you should be able to host websites at this point. Run a simple test to be sure things are running smoothly. Open a web browser on the webserver computer and go to
http://127.0.0.1 . This "magic" URL will always point to the computer you're using to browse to http://127.0.0.1 without first going through your router. Hopefully, you'll see the Apache test page using this test. Either way, let's configure No-IP.com before we forget.

Get your URL

8. Go back to No-IP.com and log in. Choose "Hosts/Redirects". Click add. Choose a hostname which will become the basis for a text-based URL for your website like "http://dave.no-ip.com". Choose "DNS Host (A)" and then "create host" or save or OK. Now No-IP.com will constantly update your website URL with your new IP addresses so that people who type http://dave.no-ip.com into their browsers will always go to the right place - your webserver! So remember: your new website's URL is now "http://XYZ.no-ip.com" where "XYZ" is the hostname you just chose. This is now your website's address on the web.
9. Open a web browser and key in your new website URL (like "http://XYZ.no-ip.com"). If all is working well, you should see an Apache logo and some sample text. At this point, you can host your website, but there are some more steps that can make life easier later so read on. And if you don't see the Apache test page and you're using a router, you'll need to configure your router.

Port forwarding

10. If you're using a router, configure your router to forward web traffic to your webserver computer (I think you have to do this even if you're just using one computer).
11. You may not know this, but since you're using a router, you have a mini-network running in your house. The router acts as a server for traffic from your cable modem/DSL to devices that are attached to it. Your router assigns a "local IP address" to any device that's attached to it so that it can send traffic to the correct devices. Imagine that your main IP address is a street address for an apartment building (your cable modem/DSL) and the local IP addresses are apartment numbers for each computer that's attached to your router. To make sure your router knows which computer should get the web traffic, you'll need to forward that traffic to the computer that's hosting your website and not to the computer that isn't hosting your websites! So you'll need to look up the local IP address for your webserving computer.

Your computer's local IP address

12. Use your webserver's OS to find its local IP address. In WinNT/2000/2003/XP, open the command prompt and type "ipconfig/all". Look for "IP address" and write this number down. Your router is probably 192.168.1.1. If just one computer is attached to your router, its local IP is probably 192.168.1.2. But you should check to be sure.
13. Next, log in to your router. Consult your router instructions if you don't know how to do this (it probably involves opening a web browser and going to "http://192.168.1.1" and logging in, hopefully with a username and password that are not the factory defaults!). Once you're logged in, go to Port Forwarding. Choose Port Forwarding and add an "HTTP" service. The start and end ports should be "80", which is the port that web traffic uses. The "server IP address" should be the local IP address for your webserver. Save it! You may want to back up your router's settings into a backup file, if possible, so you don't have to do all this again if your router crashes or you have a power outage, etc.

IP address reservation

14. If you're using more than one device off your router, another useful feature I recommend is IP address reservation. If you don't have more than one device attached to your router, you don't need to do this step. But let's say you've got two computers attached to your router and you lose power or your router crashes. Once you power up again, your router will re-assign local IP addresses to your webserver and personal computer. Those new local IP addresses may not be the same set of numbers as before you lost power! And web traffic may be routed to the wrong computer, i.e. your website is down. So you can force your router to always assign the same local IP addresses to the same devices in the event of power loss, etc.

Looking up your MAC address

15. Use your webserver's OS to find your MAC address. In WinNT/2000/2003/XP, open the command prompt and type "ipconfig/all". Look for your ethernet card's name. The MAC address is the "physical address" and looks something like this: "00-0E-58-17-79-42". Conveniently, the local IP address for this MAC address is also listed next to "IP address". Write both down.
16. Log back into your router. Go to "IP address reservation" or "LAN IP Setup". Add an address reservation. Key in the local IP address and corresponding MAC address for your webserver. Save it! You may want to back up your router settings again.
17. Once your router is configured, try your web browser again. If you see the Apache test page, you're ready to host your website!

Troubleshooting

18. If you don't, it's likely a software setting on your server computer. Try these options: make sure any firewall software is allowing HTTP traffic by designating No-IP and Apache software programs as exceptions; make sure Apache is running; try poking around the Apache software to make sure the settings seem correct; read the Apache website's documentation on getting started. Then try the web browser again.
19. Let's say it's still not working. If you're using a router, you most likely pooched an IP or MAC address. Look them up again and confirm them in the router. Make sure No-IP.com is set up and forwarding traffic to your computer properly. Make sure your router hasn't crashed after all that tweaking.

Now what do I do?

20. Make a website! Host it on your computer! How? Where do I put it? Apache creates a folder that is used as the "home directory" for your web server. On my server, Apache created a folder called "htdocs" here:
C:\Program Files\Apache Group\Apache2\htdocs. Inside htdocs, it put all the Apache test pages. I created a new folder in htdocs and moved all those test pages into it. Then I created subfolders that I use as home directories for each of my three websites. For example, there is a folder called "ski" and another called "travels". If you go to my URL (which I'll keep private, but an example might be http://dave.no-ip.com), it will be a blank web page. If you go to "http://dave.no-ip.com/ski", it will still be a blank web page. But if you go to "http://dave.no-ip.com/ski/index.htm", my ski website appears. I believe there's a setting in Apache's configuration file that allows your website to not require the "index.htm" and instead show that index.htm file as the default if someone goes to your root URL, such as http://dave.no-ip.com/ski, but I haven't played with it.
21. If you're using a second computer, it's much easier to make updates to your websites if you allow local file-sharing on your webserver. When I want to update a website, I do the coding on my PC and then open My Network Places, hop onto the correct website folder, and simply drag/drop the new file over to the webserver. Be careful and make sure you understand how to set up local file-sharing securely or you could be opening more of your computer to the outside world than you intend.

Custom URL

22. Let's say you don't enjoy long URLs like "dave.no-ip.com" and you want a snazzy one, like "AwesomeGuy.com". Yes, you can do this on your home-hosted website. Buy a URL at GoDaddy.com ($20 for a two-year registration) or a similar registration service that allows free domain forwarding. Then in your account settings, forward your domain to your long URL "dave.no-ip.com". All traffic to AwesomeGuy.com will be pushed automatically and instantly to dave.no-ip.com and your faithful website users will not have to remember dave.no-ip.com. But once they're on your website, they will see "http://dave.no-ip.com" in their browser.
23. Let's say you think any mention at all of dave.no-ip.com is lame. There are ways to show only "AwesomeGuy.com". I don't know what they are, but I'll find out and report back.

Useful resources

24. Learn how to use HTML to make websites courtesy of the super-helpful W3 Schools.
25. What's my IP address (for my cable modem/DSL)?
26. What's my bandwidth (download speed)? Try it, it's fun!
27. How can I tell, geographically, where an IP address is located? Geez, ISPs can see all that info about me? Yes, they can. Can I hide my IP address? Sort of, but I don't know how.

Caveats

28. Hosting your own website on your own computer always leaves a backdoor open for hackers. A wired NAT router, a software firewall, and normal antivirus software are good protection, but whenever you allow open access to any part of your computer, there is always a chance that someone will be able to access other parts of your computer. Here's what I've done to stay locked down without actually being on lock-down: I use a wired NAT router, my webserver is a separate computer from my PC, my webserver is running non-hacked genuine Windows that automatically updates the latest security updates and patches (though I should probably be using Linux to be even safer), my server allows file-sharing but only on my local network and only in one direction, and there is literally no personal info or data on the server except the websites.

Please leave a comment with any questions or if any of the steps above don't work for you.

No comments: