Have you ever wondered of having a web server at home or maybe at office that can be accessed from internet? Well, most small companies do not consider having in-house web server due to technical complexities, availability and security. Due to the concerns mostly related to availability, high up-time, security, financial issues most companies prefer cost effective solutions offered by hosting companies.
There is still a large audience that wants to have their own web server, mostly for research and development. So in this article we will show you how to build a publicly accessible web server at home.
Before proceeding with the tutorial its recommended to have following things ready for you.
- Computer. (Required)
- Processor: 2GHz (Preferably multi core with virtualization support )
- RAM: 3GB minimum. In-case of type-2 hypervisor at-least 6GB.
- Hard Disk: 10 GB. In-case of GUI based server 20 GB is required. More disk space is required in-case of type-2 hypervisor.
- Network: Ethernet or WLAN.
- Broadband. (Required)
- Router. (Required)
- Static IP Address. (Optional)
- Dynamic DNS such as dynu or no-ip. (Required if you don’t have static IP address)
- Type-2 Hypervisor such as VMware player. (Required in case you don’t have extra computer )
- Basic knowledge of Networks, Linux & Windows. (Required)
- CentOS 7 ISO. (Required)
- A lot of patience. (Required)
- Certainly Some Brains. (Required)
Surely, there are multiple ways to build a in-house web server. We will be using the most cheaper and faster way. Our goal is to build a web server that is similar to VPS or Dedicatied Server which we usually get from hosting companies. We are going to build our web server using following specification:
- Main OS: Windows
- Type-2 Hypervisor: VMware Player
- Guest OS: CentOS 7
- Dynamic DNS: Dynu
- Guest Hardware:
- Processor: 2 Cores will be available for guest OS
- RAM: 3GB
- Hard Drive: 20GB
- Guest Software:
- OS: CentOS7 GUI Server Installation With Development tools & Legacy Support.
- Server Management Panel: Webmin
- Web Hosting Control Panel: Virtualmin
- Available Services: Apache, MariaDB, PHP, Perl, Ruby, Bind & Postfix.
- Additional Package: Dynu client for RHEL.
Setting up Virtual Machine:
Since we are using windows for our main operating system. We are going to use VMware player to setup our virtual machine. Surely you can use any other Type-2 hypervisor if you like to.
- First of all, download the CentOS complete ISO file from here.
- Next, you will need to download the VMware Player, which is free for personal non-commercial use. Use this link to download VMware. You will be shown a list of products. Find VMware Player (under the Desktop & End-User Computing menu) and click on the Download Product link on the right:
- Next, install VMware Player on your Windows machine and start the application afterwards.
- Select File > New Virtual Machine to create a new virtual machine.
- The New Virtual Machine Wizard opens. Select the second option i.e. Install from disk and browse to the CentOS ISO file you’ve downloaded. VMware Player should recognize the version of the operating system. Click Next to continue.
- Enter the username information. The password you choose will also be used for the root account.
- Enter the VM name and the location where it will be stored.
- Select the maximum virtual hard disk size and whether you would like to store the virtual disk as a single file or multiple files.
- Click Finish to create the VM. Leave the Power on this virtual machine after creation checkbox checked.
- Once the VM boots up the CentOS installer should start. Continue with the installation. On Install Summary Page select Software Selection by-default Minimal Install will be selected. That is ok, if you are experienced in linux. If you are not familiar with Minimal Environment then choose Server with GUI. Finally, in add-ons list select Development Tools along with Compatibility Libraries. Please Note that this step is important so we suggest do not mess it up.
Configuring Network Adapter
Now that your installation is complete. We will have to configure Network Adapter before installing any packages.
- Before proceeding further, turn off your VM and go to Network Adapter Settings. By default its set to NAT change it to Bridged: Connected directly to the physical network. Now click ok to save the settings.
- Now power on the VM. Go to Application Menu > System Tools > Settings > Network > Wired > Details and note down its current IP address and MAC address / Hardware Address.
- Switch to IPv4 tab. Change IPv4 method to Manual. Set the Address to the IPv4 address you copied earlier, set Netmask to 255.255.255.0 and Gateway to your router’s IP address. If you wish you can also turn off the Auto DNS and set it to 220.127.116.11, 18.104.22.168.
- Apply the new settings. Check if the internet connection is working properly. If not then resolve the issue.
VMware Knowledge Base: https://kb.vmware.com/s/article/2013483
Visual Guide To CentOS 7 Installation: https://vitux.com/centos-installation/
Tired already? Well don’t worry the actual fun stuff is ahead. Now that, We have successfully installed CentOS. Let’s configure the LAN.
- Open your web browser and type IP address of your router e.g. 192.168.1.1 or 192.168.10.1 and press Enter. You can usually get this address from the back of your router or its brochure.
- Login to your router. Depending on your router settings find the LAN settings. For me its: Advance Setup > LAN > Static IP Lease List. Now we are going to assign a static local IPv4 address to our virtual machine. We are doing this because most of the routers are set on Automatic DHCP settings which assigns IP address on the basis of which device was connected first. Now this setting can cause IP conflict on the network.
- Add a new entry in Static IP List. Provide MAC address and Static IPv4 address your VM that we copied earlier. Save the entry. Now this IP address in particular will be reserved for your VM. Every time your router or system restarts the same IP address will be assigned to your system.
In order to make our web server publicly accessible we will have to open certain ports. This step is little bit tricky for many users so its recommended to pay attention to this.
Find and go to NAT > Virtual Servers.
- Add following ports to the to list 80, 21, 22, 25, 143, 465, 1194, 1701, 1723, 10000, 10001, 10009 and 20000 against TCP & UDP with the static ip address of our virtual machine.
- Save the list.
- Restart your router for the changes to take effect.
Your virtual server table will look similar to this example:
|Server Name||External Port Start||External Port End||Protocol||Internal Port Start||Internal Port End||Server IP Address||WAN Interface||Remove|
|Herald Lynx Server||443||443||TCP/UDP||443||443||192.168.10.13||ppp0.1|
|Herald Lynx Server||21||21||TCP/UDP||21||21||192.168.10.13||ppp0.1|
|Herald Lynx Server||22||22||TCP/UDP||22||22||192.168.10.13||ppp0.1|
|Herald Lynx Server||53||53||TCP/UDP||53||53||192.168.10.13||ppp0.1|
|Herald Lynx Server||25||25||TCP/UDP||25||25||192.168.10.13||ppp0.1|
|Herald Lynx Server||1194||1194||TCP/UDP||1194||1194||192.168.10.13||ppp0.1|
|Herald Lynx Server||1701||1701||TCP/UDP||1701||1701||192.168.10.13||ppp0.1|
|Herald Lynx Server||1723||1723||TCP/UDP||1723||1723||192.168.10.13||ppp0.1|
|Herald Lynx Server||143||143||TCP/UDP||143||143||192.168.10.13||ppp0.1|
|Herald Lynx Server||10000||10000||TCP/UDP||10000||10000||192.168.10.13||ppp0.1|
|Herald Lynx Server||20000||20000||TCP/UDP||20000||20000||192.168.10.13||ppp0.1|
|Herald Lynx Server||465||465||TCP/UDP||465||465||192.168.10.13||ppp0.1|
|Herald Lynx Server||10001||10001||TCP/UDP||10001||10001||192.168.10.13||ppp0.1|
|Herald Lynx Server||10009||10009||TCP/UDP||10009||10009||192.168.10.13||ppp0.1|
|Herald Lynx Server||80||80||TCP/UDP||80||80||192.168.10.13||ppp0.1|
Ports Still Closed ?
You will not be able to see any of above ports as opened using third party service. It is quite normal for third party services to see these ports as closed. Port checking websites show this because there are no services running yet on those ports to handle incoming connections. As a result the incoming connection is refused by the server.
Making Our Web Server Public
Since we are not using static public IPv4 address so will use Dynamic DNS. To make our virtual machine public we are going to use Dynu as dynamic dns service.
Setup Dynu Account
Register and login to Dynu Dynamic DNS Service to proceed to the following steps:
- Login to your Dynu account and go to your user control panel.
- Go to DDNS Services.
- Add a domain using Option 1.
- Type the name of your host without spaces.
- Select top level domain from drop down.
- Click on Add to save the domain. Return to DDNS Services and click on Manage Your Hostname.
- Go to bottom of page, find IP Update Password link and click on it.
- Setup your IP Update Password, note it down and Save the password. Your Dynu account is ready now.
Installing Dynu Client
Now that, our dynu account is ready it is time to install dynu client on our vm to make it publicly accessible. To install dynu client open the terminal in CentOS and use the following commands:
Enter root account password or if you have forgotten that. We suggest you update your password first.
sudo su root
Enter current account’s password.
Enter new password for root and press Enter. Confirm the password by typing it again and press Enter.
Download and install the dynu package:
rpm -ivh https://www.dynu.com/support/downloadfile/30
Edit the configuration file:
IP update client requires a configuration file with appropriate settings to function. Copy the following lines and paste them in dynuiuc.conf file:
username YOURUSERNAME # Your account username. password YOURPASSWORD # Your account password or IP update password. location LOCATIONNAME # Can be left empty. Location name can be assigned to hostnames in the control panel. ipv4 true # Can be true or false. ipv6 false # Can be true or false. pollinterval 300 # IP update interval in seconds. Minimum is 120. debug false # Can be true or false. quiet true # Can be true or false.
Below is a sample configuration which updates IPv4 address and IPv6 address for all the hostnames with location ‘Work’ in webtester account:
username webtester password somepassword location Work ipv4 true ipv6 false pollinterval 300 debug false quiet true
After editing press ESC then SHIFT + Q. To save and exit the file type wq! and press Enter.
Start the Dynu Service using:
systemctl start dynuiuc.service
Manage the service using systemd:
systemctl start dynuiuc.service
systemctl stop dynuiuc.service
systemctl restart dynuiuc.service
systemctl status dynuiuc.service
To view and truncate log files:
View live log:
tail -f /var/log/dynuiuc.log
View entire log file:
Truncate log file:
cat /dev/null > /var/log/dynuiuc.log
View service status:
systemctl status dynuiuc.service -l
Installing Web Server
Finally, we will now install the actual web server on our virtual machine. Since, there are multiple ways of setting up a web server we will be using the most convinient one. Surely, if you know your way around Linux then certainly, you can use LAMP stack manually or even XAMP server. We recommend you to install Virtualmin web hosting control panel in particular.
Since, we have already written an article on Virtualmin installation. So, you can use this guide in particular to install Webmin & Virtualmin: How to install Virtualmin on CentOS 7 VPS. Virtualmin comes with the package of Webmin thus there is no need to install them individually. Together they will allow you to easily manage your server and websites. Finish the installation using install guide and finish post installation procedure. If you find any difficulty during the Post Installation Procedure check the Virtualmin documentation provided below.
Virtualmin Documentation: https://www.virtualmin.com/documentation
Webmin Documentation: http://www.webmin.com/docs.html
Starting Dynu Service On Startup
So, after installing webserver we are going to make sure that everytime our system boots up, dynu client starts automatically. We are going to set Dynu client to start on system startup rather than starting it manually everytime. We now have two ways accomplish this.
- Manually. (Using systemd commands)
- Using Webmin.
Enabling The Service Manually
CentOS 7 uses systemd to control and manage services. Use the following commands as root to start the service on startup:
systemctl enable dynuiuc.service
You will get following output:
Created symlink from /etc/systemd/system/multi-user.target.wants/dynuiuc.service to /usr/lib/systemd/system/dynuiuc.service.
In-case of Error
If you receive an error saying
unit not found then check your spelling for mistakes. You will have to create the unit if the problem persists because without unit file you won’t be able to enable the service. Following commands will show you how to make a service unit.
Fix the permissions of executable:
sudo chmod +x /usr/bin/dynuiuc
Create a Unit file to define a systemd service:
Copy following lines and paste it in the dynuiuc.service:
[Unit] Description=Dynu IP update client daemon [Service] Type=forking PIDFile=/var/run/dynuiuc.pid ExecStart=/usr/bin/dynuiuc --conf_file /etc/dynuiuc/dynuiuc.conf --log_file /var/log/dynuiuc.log --pid_file /var/run/dynuiuc.pid --daemon ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target
Save and exit the file. Now lets try to enable the dynuiuc service again:
systemctl enable dynuiuc.service
To disable the service use following command:
systemctl disable dynuiuc.service
Using Webmin to Enable the Service
Another way to accomplish this is using Webmin. Webmin is a powerful tool. You can control or automate almost every aspect of your entire server using Webmin. So lets begin by logging in to your virtualmin root account and follow the steps mentioned below:
- Switch to Webmin from Virtualmin dashboard
- Go to System > Boot and Shutdown
- Scroll down and find dynuiuc.service
- Select the dynuiuc.service and Scroll down to find Start on Boot.
- Click on Start on Boot. The setting will be automatically saved.
Now your service will start on boot. As you can see, how easy it was to set the service to start on boot using Webmin.
Your web server is finally ready now you can either access it from LAN or form internet. You will be to able to host multiple websites on your server. All you have to do is point your domains to your server. Please note that home based servers can be good for low cost development and testing but in-reality they can’t replace hosting services provided by professional companies.