In Part 5 of the tutorial we'll buy a domain and point it to the Hetzner Server and create a Virtual Host for domain and check if it's online.
It's recommended that you have read the previous steps of this course. You'll find the overview at the end of this blogpost.
Course ingredients:
10. Buy Domain and point it to Hetzner Server
I have domains at different providers. The one I'm going to point at Hetzner Server was bought at namecheap.com. The Domain name is harusjapan.com. An eCommerce website I'm building in the third quarter of this year. If you like the japanese culture: they'll import hand selected items from Japan to the European market.
Setting the A-Record for harusjapan.com and www.harusjapan.com

@ stands for the origin which in this case is the first level domain: mydomain.com.
11. Create Virtual Host for domain
Navigate into the web directory:
cd /var/www/
Creating a root directory for the website:
sudo mkdir -p harusjapan.com/public_html/
Navigate into the new directory:
cd /var/www/harusjapan.com/public_html/
Create an index.html file which will show some content on your website:
sudo touch index.html
Open the file in the nano editor:
sudo nano index.html
Type: Hello World!

Save and close nano:
ctrl + o, press enter, ctrl + x

Open the file to check that you have saved the content:
cat index.html

Give recursive permissions to all data inside the root directory to Apache2 web server so it will show via http in the browser:
sudo chown -R www-data: /var/www/harusjapan.com/public_html

Navigate into the apache directory for available sites:
cd /etc/apache2/sites-available/
Create a yourdomain.com.conf file:
sudo touch harusjapan.com.conf
Open the file in the nano editor:
sudo nano harusjapan.com.conf
Copy and paste the content of the following code block and replace it with your specific domain names:
<VirtualHost *:80>
ServerName harusjapan.com
ServerAlias www.harusjapan.com
ServerAdmin webmaster@harusjapan.com
DocumentRoot /var/www/harusjapan.com/public_html
<Directory /var/www/harusjapan.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/harusjapan.com-error.log
CustomLog ${APACHE_LOG_DIR}/harusjapan.com-access.log combined
</VirtualHost>
ServerName: This should be your domain name.
ServerAlias: Additional domains or subdomains such as www subdomain.
DocumentRoot: The root directory from which Apache2 serves the files to the web.
Options: Server features that are available for a specific directory.
-Indexes: Prevents directory listings.
FollowSymLinks: Symbolic links are like shortcuts or references to the actual file or directory.
AllowOverride: Specifies what the .htaccess file is allowed to override in the configuration.
ErrorLog, CustomLog: Specifies the location for log files.

Now enable the new virtual host file:
sudo a2ensite domain1.com
The a2ensite helper script creates a symbolic link from the virtual host file to the sites-enabled directory.
Restart your apache2 service:
systemctl reload apache2

Check your domain in the browser. It should show the content of your index file: Hello World!
The Course Syllable:
22.05.2021 – Part 1
- Introduction & reasoning
29.05.2021 – Part 2
- Create Hetzner Cloud Server
- Connect to Server
05.06.2021 – Part 3
- Update and upgrade Ubuntu installation and install apache2
- Install PHP
12.06.2021 – Part 4
- Establish ssh keys
- Add new sudo user
- Deactivate root user
- Make new sudo user owner of ssh service
19.06.2021 – Part 5
- Buy Domain and point it to Hetzner Server
- Create Virtual Host for domain
26.06.2021 – Part 6
- Get free Let's Encrypt SSL certificates
- Request certificate, active https and force SSL
03.07.2021 – Part 7
- Install Git on Remote Server
- Create CI/CD user and ssh keys for Gitlab on Remote Server
10.07.2021 – Part 8
- Create Gitlab Repository
- Establish ssh keys and configure CI/CD
17.07.2021 – Part 9
- Install MySQL
- Install phpMyAdmin
24.07.2021 – Part 10
- Summary of project development workflow
- I'll be back – The course update log
See you next week for more
Johnnie