How To Set Up Your Own Web Server
What's special about this web server?
It's not a hosted site. It runs on an old laptop attached to my cable modem.
What's not special about this web server?
You can do it too! (provided that your ISP supports port forwarding).
I prefer to run Linux, because it plays nicely with networks. The Internet was developed on UNIX machines, and Linux is a UNIX-like operating system. However, you can also get set up under Windows or Mac. You will at least need to install the Apache web server. If you want to develop data driven web sites or web applications, you will also need:
- PHP—a server side scripting language,
- MySQL—a relational database management system (RDBMS),
- MySQL Workbench—a database modeling and administration tool.
If you're not running Linux, you might want to install the XAMPP package. This package uses MariaDB instead of MySQL. MySQL Workbench doesn't play nice with MariaDB, but XAMPP comes with the PHPMyAdmin. The nice thing about MySQL Workbench is the database modeling tool with EER diagrams. PHPMyAdmin doesn't have that, but it's an adequate database administration tool.
Under Linux, the required software can be installed using your distribution's package manager. For example, under Debian or Ubuntu, open up a terminal and type:$ sudo apt install apache2 php mysql php-mysql
You can get MySQL Workbench from MySQL Community Downloads.
If your ISP allows port forwarding, you're ready to
go live. You will need the following
- Your router's login information,
- The private IP address of the machine running Apache,
- The public IP address of your router.
If you use an Xfinity gateway, you should find your public IP address in the WAN configuration.
You want the IPv4 address.
Next you need the private address of your web server. You will find the private addresses for all devices connected to your router under "Connected Devices". I happen to have set a reserved address for my web server. It prevents hassles.
Xfinity doesn't let you set your port forwards in your router. If you go to the advanced configuration, you will see a link to the Xfinity xFi site. When you sign in, click on the connect tab near the top of the screen. Under your router name, click "see network". Then under "More" you should see advanced settings. Click on that, and you should see "Port Forwarding" on the next screen. After clicking on that, you should be able to add your port forwards. You want to forward ports 80 and 443 to the private address of your web server. My port forwards are set up as follows:
You should now be able to access your web server via your public IP address. You can test your connection by turning off WiFi on your phone (using mobile data instead) and typing http:// followed by your public IP address in your browser's address bar. (For example, the site you're reading now is reachable at http://126.96.36.199).
At this point, there is one thing that is important for you to remember. Your public IP address is a dynamic IP address assigned to your router by your ISP. It will change whenever you change your router. It also may change at the discretion of your ISP. However, if you don't physically install new equipment, your IP address will probably remain the same. It's a good idea to check your site from time to time to see if it's still accessible. If it isn't, check your router configuration to see whether your IP address has changed.
If everything has gone well, you probably want to assign a name to your IP address so that it's easier to reach. You can get a domain name from a registration service such as GoDaddy. Don't get roped into an expensive plan. All you need is domain name registration and nameserver configuration. This should only cost between $10 and $30 a year. Once you have your domain name registered, you need to add two records to the registrar's nameserver configuration: an A record and a CNAME record. The A record just contains your public IP address. The CNAME record allows you to redirect to your original domain name when someone adds a prefix. It's common for people to put www before a domain name. I have a CNAME record for "www" pointing to @ (shorthand for my base domain name) so that people will reach my site with either "www.unclechromedome.org" or just plain "unclechromedome.org". Here is the relevant section of my nameserver setup:
Finally, if your site is going to handle user input such as form data, you may want a secure certificate for the HTTPS protocol. Check out the Let's Encrypt site.
The possibilities open to you are now nearly limitless. I say "nearly" because e-mail at your domain presents an issue. You can't handle it directly on your server because your dynamic IP address won't authenticate with services such as GMail. Suppose I send email out under the address "firstname.lastname@example.org". As long as name resolution goes forward, that is, my domain name is translated into my IP address, everything is fine. I own my domain name and I can redirect it anywhere. Forward resolution is not a problem. When things go in reverse, authentication failure happens. The problem is that I don't own my IP address. I'm just "leasing" it. When the nameserver checks the PTR record to turn my IP address into a domain name, it resolves to a name assigned by my ISP (Xfinity in my case). Authentication failure happens because the names don't match. One way of dealing with this is to upgrade to business class service and get a static IP address, but that's expensive. If you want e-mail at your domain, you're probably going to have to have it hosted by a service such as GoDaddy.