Many articles are comparing different web hosting types like shared hosting vs cloud hosting or cloud vs dedicated, but it is rare to see local hosting. Can you host your website locally? Yes, you can host your site on a local computer and make it available online or use it for testing.
Why host a website locally?
Lower cost. You might already have a server at the office. You are using it for data sharing between the employees or for an email server. If it is powerful enough, you can just add extra functionality and use it as a web host. Yes, there are many disadvantages like IP address changes, keeping the server always-on, need for back up the internet and power supply, and more, but it is technically possible.
To test. You can have an identical version of your site locally and use it to test new features. That way, if something goes wrong, it will be on this local test server, and your site will continue to work. Test new software, new updates, and more in a safe environment where downtime does not matter.
How to host a website locally?
The easiest way of trying a locally hosted website on Windows is to use a WAMP server. WAMP is a package for Windows that includes Apache webserver software, Database – MySQL, and PHP.
Go to the WAMP’s site and get the 64bit version. Then install it on your computer.
When it is ready, you will see a new icon (WAMP) down on the right next to the time and date. Click on it and then navigate to phpMyAdmin. This admin panel will help you create a database.
There you need to create a root user and choose a password for the software. The next step is to click on the tab “Databases”, write the name for your database, and click create.
For this example, we will install the WordPress CMS. You can go for Joomla or another if you like and still follow the instructions.
So, we will go to WodPress.org and press the button “Get WordPress”.
You will get a zip file that you need to extract in “C:\wamp64\mysite” (change “mysite” with the folder you have chosen or create a new one).
Open your browser and write the following in the address bar:
So finally, the installation process of WordPress begins. There you will need to add data from the previous steps about the database. Use the user “root” and the information about the database you recently created.
Continue with the installation process by choosing site’s name, username, password, and additional information.
Now you have successfully installed a WordPress site on your local hardware!
Your Localhost online, how?
By now, we have created a WordPress site, but only you can use it. We will need to change a few things so it can be available online.
Let’s go to the configuration of Apache:
Open it with Notepad or another text editor, find the “Listen 80” and change the 80 number with your IP address. Find your IP address in some of the “What’s my IP address site” if you don’t know it.
So now it will look like “126.96.36.199:80”.
Then change the second thing that is “ServerName” with “ServerName YOUR IP ADDRESS”.
Then find “c:/wamp/www/”, and under it, you need to change the permission to:
Allow from all
Restart your Localhost, and everybody can get to your website by using the IP address.
Adding a domain to your site
Now the site is accessible only with the IP address. You can go and buy a domain from a domain register site and use it to provide access to the site.
Buy a domain, and in the control panel of the domain provider, you will need to add an A DNS record that connects the domain to your IP address where the site is hosted.
We are not finished yet. If your IP address is not static, you will need to do some more.
Go to the settings of your router. You will need to find NAT, virtual server, or forwarding.
We need to forward the port, so when your IP address changes, you don’t need to change the A record manually.
Forward the WEB or HTTP traffic to port number 80, and in the field, LAN IP Address, add the IP address that your device uses on the local network (not the previous IP address that we used). Apply the changes and save.
Now it is ready!
You can use a very similar approach for mac computers with MAMP and LAMP for Linux.
Creating a website locally is possible, but currently, it is worth it, only for testing.