Step 1: Create Website Directory
A directory for the website was created inside /var/www to store the website files.
sudo mkdir /var/www/tictactoe.com
This directory acts as the DocumentRoot for the website.
Step 2: Create Website Files
An index.html file was created inside the website directory.
sudo nano /var/www/tictactoe.com/index.html
This file contains the static Tic Tac Toe game content and serves as the homepage of the website.
Step 3: Create Apache Virtual Host Configuration
A virtual host configuration file was created in /etc/apache2/sites-available.
sudo nano /etc/apache2/sites-available/tictactoe.com.conf
Virtual Host Configuration
<VirtualHost *:80>
ServerName tictactoe.com
ServerAlias www.tictactoe.com
ServerAdmin [email protected]
DocumentRoot /var/www/tictactoe.com
ErrorLog ${APACHE_LOG_DIR}/tictactoe_error.log
CustomLog ${APACHE_LOG_DIR}/tictactoe_access.log combined
</VirtualHost>
Explanation:
- ServerName – Primary domain name.
- ServerAlias – Alternate domain name.
- DocumentRoot – Location of website files.
- ErrorLog – Stores Apache error logs.
- CustomLog – Stores Apache access logs in combined format.
Step 4: Enable the Virtual Host
The newly created site was enabled using:
sudo a2ensite tictactoe.com.conf
This creates a symbolic link in /etc/apache2/sites-enabled.
Step 5: Verify Apache Configuration Includes Sites-Enabled
The Apache main configuration file was checked to ensure virtual hosts are included.
Cat apache2.conf | grep IncludeOptional
Verified the following line exists:
IncludeOptional sites-enabled/*.conf
This ensures Apache loads all enabled virtual hosts.
Step 6: Update Hosts File
The domain name was mapped to the local IP address in /etc/hosts for local testing.
sudo nano /etc/hosts
Added entry:
127.0.1.1 www.tictactoe.com
This allows accessing the site locally without DNS.
Step 7: Reload Apache Server
Apache was reloaded to apply all changes.
sudo systemctl reload apache2
After reloading, the website was successfully accessed using:
http://tictactoe.com
Monitoring via Access and Error Logs
Understanding logs is vital for maintaining a healthy server.
• Overall Access Log: Located at /var/log/apache2/access.log, this records every HTTP request handled by the server. It is used for monitoring traffic and identifying suspicious access attempts.
• Site-Specific Logs: By defining custom logs in your Virtual Host, you can isolate traffic for just one site (e.g., /var/log/apache2/tictactoe_access.log).
• Error Logs: The file /var/log/apache2/tictactoe_error.log captures runtime errors and permission issues, which is essential for debugging when a site fails to load.
You can view these logs in real-time using the command sudo tail -f followed by the log path

