Learning to code and want to host a website at your house? While it is not a business solution, it can be a fun thing to do. In this post we’ll go over the essentials for hosting a website from your own home, as well as why it’s not a great idea to do this for your business.
Before you Start:
You will want to check your ISP’s rules regarding hosting a website with residential internet service. Many ISPs do not allow hosting websites from your residential internet connection.
In example: Charter’s Terms of usage for Residential Internet:
“Prohibited Activities Using the System, Network, and Service. Any activity or use of the Service which violates system or network security or integrity are prohibited and may result in criminal and civil liability. Such violations include, without limitation, the following:…
…Running any type of server on the system that is not consistent with personal, residential use. This includes but is not limited to FTP, IRC, SMTP, POP, HTTP, SOCS, SQUID, NTP, DNS or any multi-user forums.”
Performance and Uptime: Is it really worth the 0$ price tag?
While there are no extra fees attached to hosting a website from your home, making it cheaper than paying for hosting, you will not see the same kind of performance and bandwidth that hosting your website on a dedicated hosting server will. When a client makes a request to a web server, the server will *upload* the data, or, send the data out from its LAN through its ISP, out through the internet, and eventually to the client’s address.
The upload speed on residential gateways is throttled because it is not expected or desired by ISPs that residents upload large amounts of data. Residential upload speeds are usually anywhere from half to a tenth the download speed. For example, my home internet speed is 60 mbps *download* and 5 mbps *upload*.These speeds are not compatible with serving large amounts of data. Nor also is your home impervious to power outages, internet outages, and the regular inconsistencies that residential internet is subject to. But if your plans only consist of hosting a small non-business website which not many people will access and for which downtime is tolerable, this is a more reasonable solution.
Step One: Set aside a Dedicated Machine
In order to host a website, you need a dedicated (read: always on) computer at your house that is connected to your LAN with a wired connection. You could use a Windows, Linux, or MacOS Operating system. You could also create a Virtual Machine to run inside Windows, Mac, or Linux computer. In the future I’ll be making a post on creating a virtual machine, so look out for that.
Static IP Addressing
Another part of setting up a dedicated machine is setting a static IP address. This is a very simple step which requires that you access your network settings on this computer and ensure that the computer’s IP Address does not change (so that traffic can be forwarded from the firewall to your server).
For a guide to setting a static IP address in Windows, please see Microsoft’s Technet Article.
To set a static IP Address on a Mac Computer, please visit OSX Daily’s tutorial.
The last step towards ensuring that your dedicated computer fits the criterion of a “dedicated” server is to ensure that your power settings are such that your PC never goes to sleep after a certain amount of time. In Windows, you can change these settings in “Power Settings” in the start menu. In Mac, you can change these settings from System Preference -> Power Saver.
In conclusion, make sure your computer is 1) Connected to your network with an ethernet cord, 2) has a static IP, and 3) has power settings to never go to sleep.
Step Two: Install Apache
Apache is a service which runs on your PC to serve requests sent to your computer on port 80 (HTTP), 443 (HTTPS), or another manually specified port. By default, when Apache is installed, it listens on port 80.
Once the service is installed, it will create a root directory on your computer in which you can store the files which your computer will present when it’s address is visited, for example: index.html or style.css.
To install apache on Windows, download and install the latest stable release of apache from their downloads website.
Apache Installation Instructions for Windows:
Download the .zip folder containing apache files and unzip it. Place the folder entitled “Apache24” on your C:\ Drive.
Open an admin command prompt, and navigate to C:\Apache24\bin. Once there, run the command:
httpd.exe -k install
This will install Apache as a service on your PC.
Next, run the command to start the apache service:
net-start apache2.4 (service name may vary depending on current version)
Once Apache is installed, you will be able to place any documents you want to be accessible by web-browsers in the “htdocs” folder. With the apache service running, if you go to your web browser on this computer and type in http://localhost, or localhost:80, you should see either the contents of the index.html file or the directory listing of the files in htdocs.
Note that Apache by default reads index.* files by default. So if you do not want a list of documents stored in your htdocs folder to show up when one visits your website like so:
… you’ll want to include a file called ‘index.html’, or ‘index.php’, if you’re writing in php. Apache will automatically read and render the contents of index.html and other files types such as index.php.
Congrats! If you can visit your webserver’s IP address or localhost:80 from your server’s web browser and see the apache “It works!” message, you’re most of the way there. From another computer or smart phone at your house (connected to the WiFi) you should be able to visit the IP of your web-server and see this page. Your only obstacle now is that the outside world can’t see your content. You’ll need to create rules in your router to allow the outside world to visit your site.
Step 3: Set up Port Forwarding in your Firewall/Router
The next step will require that you have access to the firewall at your home. The IP of your router will usually be your default gateway for your computer. Log in to the web interface of the router/firewall and locate the setting for Port Forwarding/Triggering. You may also find it under “NAT” or “Firewall Rules”. My best advice for locating this setting, if you cannot find it, is making a quick search for ‘port forwarding settings’ for your router model.
The necessity of port forwarding stems from the fact that most home routers these days act as firewalls. They do not allow any unsolicited traffic in to the Local Area Network on their WAN (Internet) port unless you specifically instruct them to do so by creating port forwarding rules.
By default, Apache server listens on port 80, so what you will want to do is set a port forwarding rule from port 80 externally to port 80 internally, then direct it to the static IP address you set for your server. If your server does not allow you to set custom rules, you’ll want to use the ‘http’ port.
If you open Google Chrome and search ‘my ip’, you can find your Gateway Address, or, Public IP. If these port forwarding rules are working correctly, when you visit this gateway address from another computer outside of your network, you should now be able to see your website.
Step 4: Set up Dynamic DNS / Custom Domain Name
The problem with visiting your home-hosted website from outside is that you have to remember your external IP address to get to it. Not only that, but sometimes your public Gateway IP will change because your ISP assigns you a new address due to your modem going offline or something of the like.
There are a few solutions to this: 1) you could just write down your external IP or save it as a favorite in your browser, updating it every time it changes, 2) you could purchase a standard domain name and update the DNS ‘a’ record every time your public IP changes, or 3) you could sign up for a dynamic DNS domain name.
The most common solution for home-hosted websites is to sign up for a dynamic DNS address, such as exampleaddress.dyndns.com.
There are a few free dynamic DNS services such as no-ip.com. Dynamic DNS requires that a device from your network sends updates to their servers so that they can continually keep track of your public IP and associate it with your domain name.
You can continually update your public IP address with their Dynamic DNS Updater running on your server, or you can send them from your router if it has the capability. To check this, access your router’s web interface and navigate to the “Dynamic DNS” section.
Once you’ve set up your dynamic dns hostname, you should be able to visit this address to access your website outside of your home.
Good luck and happy web-designing. (P.S., now you’ve got to design the website) If you have any questions feel free to post in the comments below.