How to Host Your Own Website
Hosting your own website is an experience as entertaining as it is rewarding. Using an old Windows or Linux machine, you can throw a few HTML files into a folder and put them on the internet all by yourself.
It’s important to know exactly what you’re doing when hosting a website, though. Your computer will act as a server, a machine built with the purpose of storing and sending your data across the internet, allowing your site to appear to anyone in the world.
Essentially, that’s all web hosting is. Your machine is merely a tool for housing data and uploading it to the network. However, there are some other pieces of software that ensure this process runs smoothly.
Before diving in, we’d like to make a note. We’re putting up this guide for educational purposes only. We don’t recommend you host your own website, as it’ll bring too many performance and consistency issues. If you’re serious about putting up a website, try out Hostgator or SiteGround, two of our favorite hosting providers for ease of use, pricing and speed.
How to Host Your Website at Home
We’re going to run over how to host your own website on Windows and Linux using your home machine and a normal desktop environment. Our tutorial will help you put up a test website, but it’s up to you to design it.
For our tutorial, we’re using the AMP stack. Don’t worry if you’re not familiar with this term yet, as we’ll run through each of the technologies throughout the tutorial.
Hosting on Windows
If you have an extra Windows computer gathering dust, you can turn it into a web server. The process is fairly straightforward, aided by the AMP stack. This bundle includes Apache, MySQL and PHP, commonly referred to on Windows as WAMP. I’m sure you can discern why.
There are several installation programs, but we’ll use WampServer because it’s the most straightforward. Head to the Wamp server website and download either the 32-bit or 64-bit executable, depending on your OS.
If your machine has Skype running during the installation, you’ll get a “port 80” conflict. WampServer and Skype both use port 80, so simply disconnect from Skype before running WampServer and you’ll be fine.
It will automatically create a “www” directory, which is usually found at “c:\wamp\www”. This is where your website (or websites) will live. Simply create a new folder in the directory and house your PHP or HTML files inside.
Before you do that, though, you need to test that WampServer is working properly. You can access the main screen of WampServer by either clicking on the link in the menu or opening a web browser and going to “http://localhost”.
Testing WampServer
Congratulations, your Windows computer is now a server, but it’s not really doing much right now. We need to test it to make sure that everything is flowing properly before adding your files and making them live on the internet.
We’ll make a simple test PHP file and put it into the directory. Open up NotePad in Windows and enter the following line:
<title>PHP Test</title>
Save that file as “info.php” in the “www” directory created by WampServer. Open your web browser back up and head to “http://localhost/info.php”. If you see a blank page with “PHP Test” on the tab name, then everything is running how it should.
Configure MySQL Databases
If you aren’t using a CMS like WordPress (if you are, you may want to read our guide on the best web hosting for WordPress), you’ll need to configure your MySQL databases. This is an open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).
For a less acronym-focused definition, MySQL organizes the data of your website into a database that can quickly find and transmit that data. A Content Management System (CMS) uses MySQL as a way to send that information off as efficiently as possible to the user.
You can alter existing databases or create new ones by clicking on “phpMyAdmin” in the “tools” section of the Wamp Server main screen. It’ll open a new tab requesting a username and password. The username will be “root” by default, and you can leave the password field blank.
If you plan on using a CMS, you may never need to dive into this area. For example, WordPress will create a MySQL database for you when it installs. Either way, it’s a bad idea to poke around here unless you know what you’re doing.
To ensure that MySQL is working properly, though, open up a new tab and go to “http://localhost/testmysql.php” — it will show you the IP address of your machine and let you know if the connection is good or not.
Make Your Website Live
The Apache configuration file is set to deny any incoming connections by default. That means your local machine is the only one that can access your website. This is good for getting a test site running, but you’ll need to change the configuration once you’re ready to go live.
Go to the WampServer menu and click on “Apache” and then “httpd-vhosts.conf”.
This is your Apache configuration file, and it should have the following lines inside:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot “${INSTALL_DIR}/www”
<Directory “${INSTALL_DIR}/www/”>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
To allow incoming connections, simply change “require local” to “require all granted” and you’ll be good to go.
Restart WampServer by selecting “restart all services” in the menu, and the changes will take effect. You may need to double-check that your PC firewall isn’t blocking web requests, but it should be set after that.
Adding a Domain Name
No one is going to memorize the folder hierarchy to access your website, though. You’ll need a domain name that points back to your local machine for easy input into any web browser. The server does so with DNS records.
You can read our article on DNS records to learn the specifics, but basically it’s a system that ties your local IP address to a domain name. For example, if your server IP was 199.999.999, then the DNS records would know to access that server when your domain name is keyed in.
Once you have an a record for your domain in the DNS records, you need to update your local host file. Go to “C:\Windows\system32\drivers\etc\hosts file” and add the following line to the bottom (don’t include what’s in parentheses below):
199.999.999.99 (your IP address) example.com (your domain name)
Next, you need to add a file manually into “C:\wamp\bin\apache\Apache-VERSION\conf\extra\”, where VERSION is your version of Apache. Create a file in NotePad with the following lines:
ServerAdmin [email protected]
DocumentRoot “c:\wamp\www”
ServerName mysite.localErrorLog “logs/example.com.log”
CustomLog “logs/example.com-access.log” common
Of course, replace “example.com” with your domain name. Once your domain name is set, save the file in the Apache directory and your website will be accessible via its domain name.
Tips for Windows Hosting
Although a normal machine will get you up and running, it’s the not the most ideal setup considering Windows is one of the more resource-intensive operating systems. Unless you have a lot of power to play with, you’ll need to optimize the operating system for web hosting.
The first step is to uninstall every application that you won’t be needing. Although keeping a web browser around is crucial for accessing the WampServer control panel, nearly everything else can get the ax.
Next, disable any startup applications that may be running in the background. There are a few applications that Windows needs in order to operate, so use your best judgment on which to disable. You can find the list in the task manager.
If you’re serious about using a Windows machine for web hosting, then it’s worthwhile to invest in a copy of Windows Server, as well. This OS is much more lightweight, streamlined for running on any server, whether it’s for web hosting or just for storage.
Hosting on Linux
If you plan on building a machine from scratch, then Linux is probably the better choice. This lightweight piece of kit is the chameleon of operating systems, allowing you to adapt it to nearly every need.
The process is similar to Windows, except you need a LAMP bundle instead of a WAMP bundle. I’m sure you can figure out the difference. To retrieve the stack, open up the terminal and enter the following line:
sudo apt install apache2 mysql-server php libapache2-mod-php7.0
During installation, you’ll be asked to set a password for the “root” user. You can set it to whatever you want or just leave it blank. Once the installation is complete, you’ll need to restart the Apache web server.
You’ll need to do this any time you change the global configuration of Apache unless you do it using the local .htaccess files. To restart, enter the following command:
sudo /etc/init.d/apache2 restart
Check PHP
Like with Windows, we need to confirm the PHP server works before moving forward. We’ll use the same process as before by placing a test file into the “www” folder that, on Linux, is found at “/var/www/html/”. Create a file with the following line and place it in the directory:
sudo echo “” > /var/www/html/info.php
Head to “http://localhost/info.php” and see if the page loads. You should be able to see the PHP version, current configuration and installed modules here as well.
Configure MySQL
After confirming PHP is working, it’s time to check the MySQL databases. If you plan on using a CMS like WordPress, it’s important not to skip this step.
Open the terminal and enter the following line:
service mysql status
After a few moments, you should get this result:
$ service mysql status
- mysql.service – MySQL Community Server
[…]
mrt 15 16:02:14 host1 systemd[1]: Started MySQL Community Server.
If the server isn’t working, just type in “sudo service mysql restart” to restart the MySQL server. After you get it working, you can use the MySQL command line client to manage your databases. To do so, recall the credentials you entered when MySQL was installed and enter the following:
$ mysql -u root -p
Usually, a CMS will install the database for you, so you won’t need to fuss around here. However, there are a few things you can do manually, such as create a backup of your databases. For those who want a more user-friendly way to do so, you can install PHPMyAdmin by entering the following line:
sudo apt install phpmyadmin
It’s an easy-to-use database management tool that circumvents the lines of code for managing your databases.
Configure Apache
The last step is to allow Apache to accept incoming web requests from the domain name in your DNS records. If you need help setting up these records, contact your DNS hosting provider because they should have an online tool for you to configure them.
Enter the following lines in the terminal:
sudo mkdir -p /var/www/html/example.com
sudo sh -c ‘echo “<title>example.com</title><h1>This is my self-hosted site example.com</h1>” > /var/www/html/example.com/index.html
sudo chmod -R 755 /var/www/html/example.com
This sets up the directory for your domain. You need to set up a “virtual host” file for Apache to see the page, though. Enter the following lines:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
And
sudo nano /etc/apache2/sites-available/example.com.conf
Now, edit the Apache file to match this:
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Reload Apache for the changes to take effect by entering the following:
sudo a2ensite example.com.conf
sudo service apache2 reload
Like with Windows, simply add your IP address and domain name to your machines hosts file to match it locally.
Pros and Cons of Hosting Your Own Website
Not everything is great about hosting your own website, though. The initial cost savings of not paying for a hosting plan is about the only upside, but even that falls short in the long run.
Running your own server will rack up the electricity bill faster than you can say “shared hosting.” Your server will need to be turned on and connected to the internet all the time, so the cost will actually end up far higher than buying an inexpensive web hosting plan with a hosting company.
That’s not even considering the potential for internet outages in residential areas. If your area is prone to frequent internet connection outages, your website’s stability will be all over the place, especially without a high-powered internet service provider to back it up.
Costs are high, but the practicality of hosting your own website just isn’t there. Your website will be victim to slow connections, hurting it in Google search rankings and turning away potential visitors. While many inexpensive hosting providers deal in the one to two second range, a residential connection will probably deal in the 15 to 20 second range.
The process of putting your own website online is best used as an educational tool to understand how web hosting works. By exposing yourself to all the website-hosting tools, you’ll be able to configure your website better with an external host.
If cost is a concern, check out our list of the best cheap web hosting options, where we break down providers that give excellent service at decent rates. Our favorite option there is iPage.
However, hosting a website is certainly an option for staging or if you plan on running a small WordPress blog. If that’s you, make sure to check out our guides to using WordPress.
Conclusion
Hosting your own website is about as much fun as geeks (like us) can have. It’s an opportunity to play with new tech toys on old hardware, and learn more about the web hosting world and how it functions.
Unfortunately, that’s its best use. Unless you have some serious power behind your server, it’s difficult to make hosting a website a viable option, both practically and monetary. For that, we’ve ranked the best web hosting providers, so you can make an informed choice.
Are you ready to get started and eager to host a website? How did your home hosting experience go? Will you use a web hosting service instead? Let us know in the comments below and, as always, thanks for reading.