Have you ever thought you could create your own hosting at home or turn your computer into a VPS or not? In the past, many times I wanted to make a server at home to run a website for less than $ 5 / month to rent vps at the services provided. Due to very complicated device conditions and server configuration at home, it won’t be until 2020 to make a home server to run the website. It’s a server for it, but it’s actually a NUC computer with Ubuntu and Cyber Panel installed.
Demo, try it out: https://bdsvip.tientv.xyz
In terms of performance, I am completely satisfied when I host my website at home. However, in terms of stability, it is not possible because there are many issues that need attention and are not easy to overcome. For example, the most common case I encounter is a power outage…
1. Prepare before building a server at home
- Computer, laptop, Nuc connected to the network and can run continuously as a server.
- USB 4Gb
Operating system: You can use CentOS, Ubuntu Server, Fedora, and more. However, in this article I will install Ubuntu Server.
Note: When downloading Ubuntu, remember to choose the version Server install image
Control Panel for VPS: You can use paid panels like Direct Admin, Cpanel … for better support and higher security. However, with this home server, it is best to use Free. I recommend aapanel or Cyber Panel. I have used through these 2 free Panels, I find it fast, stable, good security, but Cyber Panel is better for dividing users.
In this article I will use Cyberpanel: https://cyberpanel.net
To install Ubutum server, download ubuntu and create a bootable usb to install Ubuntu according to the instructions: See instructions for creating Ubuntu bootable usb
Note: Before installing, you should delete all partitions in SSD
Try USB boot to install Ubuntu on the computer running boot from USB. If successful, you will receive a screen to choose the language to install Ubuntu as shown below:
You choose as shown in the picture to go to the next step
Click Done to go to the next step. Here you should plug in the network cable or connect to Wifi first so that it receives the IP from the modem always, without having to configure it manually.
Note: record the network IP so that when the installation is complete, use it. My ip above is: 192.168.142.141
Click Done to go to the next step
In the picture above, I use a 30GB drive. See if the SSD capacity is displayed and then click Done to go to the next step.
Note: This step will not use up your SSD space by default. So you need to maximize the SSD capacity as shown in the red underline in the image above. My drive is 30GB, divided by 1GB boot to 28.99GB. Click on the red brick line and adjust the capacity by the line above it. -> click Done to go to the next step
- Your name: Enter an arbitrary name, do not enter special characters
- Your server’s name: Enter the server name written immediately without accents
- Pick a username: Server administrator login name, write immediately without accents, do not enter words admin
- Password: Password to login to the server, remember to enter after entering.
Click Done to go to the next step
This step you use the key Space to highlight the installation option: Install OpenSSH Server
Press Done to go to the next step
Leave this step as default and click Done
This installation process takes about 15 minutes more, after successful installation select Reboot Now to reboot the machine (remember to remove the USB).
Reboot is done, successfully installed Ubuntu Server
3. Install Cyber Panel to manage the server
To install Cyber Panel, I connect SSH to the server using Mobaxterm to install it easily. Convenient copy and paste.
My server IP above is: 192.168.142.141 – Please see the instructions on how to install Mobaxterm that you have left at the top of the article.
sudo su -
Paste the Cyber Panel install command into
sh <(curl https://cyberpanel.net/install.sh || wget -O - https://cyberpanel.net/install.sh)
Wait a moment, choose number 1 to install CyberPanel
Process check completed… CyberPanel Installer v2.0 1. Install CyberPanel. 2. Install Addons. 3. Exit. Please enter the number[1-3]: 1
You choose: Choose 1 Install CyberPanel with OpenLiteSpeed
CyberPanel Installer v2.0 RAM check : 81/991MB (8.17%) Disk check : 1/25GB (6%) (Minimal 10GB free space) 1. Install CyberPanel with OpenLiteSpeed. 2. Install Cyberpanel with LiteSpeed Enterprise. 3. Exit. Please enter the number[1-3]: 1
Select y and enter to install Full
Install Full service for CyberPanel? This will include PowerDNS, Postfix and Pure-FTPd. Full installation [Y/n]: y
Press enter to not install Remote SQL by default
Do you want to setup Remote MySQL? (This will skip installation of local MySQL) (Default = No) Remote MySQL [y/N]:
This step installs Cyber’s Pass (Different from Ubuntu’s pass) press enter default is 1234567 Or you enter your password: I leave it as default and change it later
Please choose to use default admin password 1234567, randomly generate one (recommended) or specify the admin password? Choose [d]fault, [r]andom or [s]et password: [d/r/s]
Next, it will ask you something like: install Memcached, LiteSpeed Memcached, Redis. I choose
y to install all.
Please choose to use default admin password 1234567, randomly generate one (recommended) or specify the admin password? Choose [d]fault, [r]andom or [s]et password: [d/r/s] r (Lưu ý: chọn R để random pass admin) Admin password will be provided once installation completed… Replace JS/CSS files to JS Delivr? This may improve panel loading speed in Asia Pacific region… Please select [y/N]: y Install Memcached extension for PHP? Please select [y/N]: y Install LiteSpeed Memcached? Please select [y/N]: y Install Redis extension for PHP? Please select [y/N]: y Install Redis? Please select [y/N]: y
Finally, you wait for the installation process about 10-15 minutes, after successfully installing CyberPanel you will receive the following login information:
At the visit: in the picture is your IP outside the internet environment, now you have not nat port can’t get out. Therefore, you need to change the IP to your local IP (the IP that SSH is using now: 192.168.142.141).
So you have installed CyberPanel for VPS already. Now login to CyberPanel via
192.168.142.141:8090 with the above information.
3. NAT Port Modem for server
(NAT) port Allow data to pass through network devices such as modems, wifi routers …, without being blocked by a firewall, allowing the domain to your home IP, then that domain can access your installed web server.
NAT Port on modems: This is for reference only, not all modems are the same and to access these settings you need to know the admin account to log in to the modem (if not, please ask for the network operator).
Step 1: Access the modem in use. The modem I’m using is Viettel’s with the access address, user and password listed below the modem: 192.168.1.1
Step 2: Assign default IP to your server
- You go to Finland in the Modem to find the Ip that your device received when installing ubuntu as mine is: 192.168.142.141. See what the server’s Mac address is. Example: 54:27:1e:e4:1e:9d
- Go to section DHCP Binding to assign IP to your server. For when starting the server, the modem will default to the assigned IP and Server. That way, our Nat parts are not faulty.
Note: You should choose the rarely used IP range according to the modem to assign.
Step 3: Nat Port
- Go to Security > DMZ Host (Depending on each modem, find the DMZ): In this section, you must enter the IP of the server assigned above. When accessing outside of my home network, the default is to go to the server instead of other computers in my home network.
- Switch to Port Forwarding to let Nat the ports below.
Please make sure you have opened following port for both in/out: TCP: 8090 for CyberPanel TCP: 80, TCP: 443 and UDP: 443 for webserver TCP: 21 and TCP: 40110-40210 for FTP TCP: 25, TCP: 587, TCP: 465, TCP: 110, TCP: 143 and TCP: 993 for mail service TCP: 53 and UDP: 53 for DNS service
Note: The image above is an example of porting 8090. You have to do the above ports in turn.
That’s it, Nat Port is done come in to check whether the broken port is successful. As shown below is success
4. Automatically update dynamic IP for domain name.
Internet at home, the default IP WAN (My IP address outside the internet) will change continuously. So when you use the domain name to access the server at home, it is imperative to adjust the DNS when the WAN IP changes. This section instructs automatic DNS updates for domain names.
Note: If your home has conditions to use a provincial IP, skip this step
To be able to change IP automatically, I use Cloudflare to do it. The advantage of Cloudflare is that DNS updates are extremely fast and there is a federation API to do it.
Install and configure Cloudflare
Step 1: Register an account and Transfer DNS domain name to Cloudflare.com -> Search google a few steps and you’re done
Step 2: Get the Cloudflare API -> After adding the domain name to bring to the host, you will see the API
git clone https://github.com/LINKIWI/cloudflare-ddns-client.git
sudo apt install python-is-python3
sudo make install
- Choose [T]oken or [K]ey: choose a letter KY then Enter.
- Email: your cloudflare login email
- API Key: paste the API Key you got from step 2.
- Comma-delimited domains: enter the domain you need to update the IP in, multiple domains are separated by a semicolon (,)
When you receive the notification Configuration file written…. successfully. Type the following command to update the IP to your domain
Add cron job to automatically update IP
Choose 1 to continue
In the crontab editing interface, you add this line at the end and save. This line means that after 5 minutes, the IP will be updated once, you can change it to your liking.
*/5 * * * * /usr/local/bin/cloudflare-ddns --update-now
Press Ctrl + Z to exit the editor.
Finally: Restart the server.
To check, try turning off the Modem and see if CloudFlare updates the IP.
So, I have guided you through the most detailed steps to build a private server at home for research and development. In fact, you can use this server to run demo webs for customers or use it as the main VPS for your websites.