Final Project Deliverable 2

Video:Deliverable 2 Latest Video 0-100!

Part 1 Virtual Machine

Create a virtual machine that meets the following specifications:

  • CPU: 1 Core
  • RAM: 1 GB
  • HDD: 10 GB

These are the recommended system requirements for Ubuntu Server 22.04. Ubuntu Server VM Settings

Part 2 Install Ubuntu Server

Step 1

Step 1

Step 2

Step 2

Step 3

Step 3
Select Update to the new installer. This will update the Ubuntu installer and proceed with the installation.

Step 4

Step 4 This step will automatically select the language layout of your keyboard. If for whatever reason it is different than what your physical keyboard has, then manually adjust it.

Step 5

Step 5
Choose the default Ubuntu Server installation. We will need some of the repositories in the default installation.

Step 6

Step 6
Since we are installing Ubuntu in a virtual machine that at the moment is configured to have a NAT network interface card, as long as your host PC has internet connection, you should automatically get an IP address. If you don’t, something is wrong with your VM, Host Machine, or Internet Connection.

Note: If you are doing this project in the school’s network, be aware that the school’s routers are configured to block Bridged Ethernet adapters.

Step 7

Step 7
Leave this part empty as we are not using a proxy.

Step 8

step 8
We will use the default mirror so there is no need to change this

Step 9

Step 9
This step is to format our disk. Here we will select the entire disk. To move around here use either the arrow keys or the tab key.

Step 10

Step 10
Step 10.1
This step is just to let you know the changes that will be made to the server’s virtual hard drive.

Step 11

Step 11
Here you will enter the information about your computer. Write this information down because you will needed it later.

Step 12

Step 12
It is a good idea to install ssh now as we will use it later on. Do not import SSH keys. We will do that manually later.

Step 13

Step 13
Do not select these services. We won’t be using them.

Step 14

Step 14
This is the installation process. Once it is done it will start updating the system. Once the update is done, it will ask you to reboot.

Step 15

Step 15

Step 16

Step 16
Here Just press enter. Virtualbox will unmount the installation disk for you

Part 3 Install Apache

First, login to the server. You will need to type your username and password. Here is an example: log in
Notice that the password is hidden while typing just like when you are typing it in the terminal emulator. Be aware that during the upgrade, Ubuntu will ask you to restart some services.

Apache is available in Ubuntu’s default repositories. However, before we can start installing new packages, let’s update the system:

sudo apt update; sudo apt upgrade -y

Update Ubuntu

To install Apache use:

sudo apt install apache2 -y

install apache
Be aware that here you will also need to restart some services here.

Part 4 Setup SSH

Before Setup

Before we can setup SSH, we need to enable the firewall. Use this command:

sudo ufw enable

Now lets configure ufw to allow Apache and SSH traffic:

sudo ufw allow 'Apache'
sudo ufw allow 'OpenSSH'

Now check the status of the firewall:

sudo ufw status

firewall

Now lets check the status of Apache and SSH to make sure they are running:

systemctl status apache2 --no-pager
systemctl status ssh --no-pager

Both commands should return active (running) if they do not, restart the services with the command:

sudo systemctl restart apache2 ssh

service status check

Change the Network Adapter

Follow these steps:

  1. Turn off the server virtual machine using this command:
    sudo shutdown now
  2. Change the server network adapter configuration from NAT to Bridge. Network Adapter

    However, there is a chance that using a bridge adapter won’t work for you. Some IDS (Instruction Detection Systems) and smart routers may prevent you from getting an Ip Address if your Network Adapter is bridge. In this case, you need to use port forwarding in your virtual machine. Here is an example:

portforwarding

Connect with SSH

ssh connection

Follow these steps:

  1. Make sure SSH is installed in both the client and the server:
    sudo apt install openssh -y
  2. In the server, the SSH service must be already running, if it is not running, use this command to enable it and start it:
    sudo systemctl enable ssh; sudo systemctl start ssh
  3. You will need to get the IP address of the server. Use this command to get the IP address: hostname -I. Additionally, you can setup a static IP address in your server. Here is a guide on how to do it. If you are doing this project in your laptop, I advise to stay away from setting up static IP addresses.
  4. On the client computer use this command:
    ssh syntax
    ssh connection
  5. If you are using port forwarding, your command would be:
    ssh -p 2222 username@127.0.0.1

Setup private and public key authentication with or without password (optional)

  1. On the server, configure the firewall to accept ssh connections.
    sudo ufw allow ssh
    sudo ufw enable
    sudo ufw status
    
  2. Now we need to generate an ssh key in our client computer: In your client machine type:
    ssh-keygen Now you can type this command to copy your ssh key to the server:
    ssh-copy-id -i .ssh/id_rsa.pub webmaster@server-ip-address

  3. if you use port forwarding your command will be:
    ssh-copy-id -p 2222 username@127.0.0.1
  4. Now you can connect to your server without having to remember the password.

Part 5 Setup virtual hosts

Virtual host allows us to serve more than one website in a single web server. By default, Apache has one server block enabled. This server block is served from the directory: /var/www/html. For a single website, all the files are placed within this directory. When we setup virtual hosts, each site has its own directory. The recommendation is to leave the default html directory and for each site a new directory inside /var/www. In this project, we will have one virtual site called mywebsite. You are welcome to use a different name just remember to adjust every command where the word mywebsite is reference for your preferred website domain name.

Follow These Steps

  1. Create the directory for mywebsite as follows:
    sudo mkdir /var/www/mywebsite
  2. Modify the ownership of mywebsite so that it is now owned by your user instead of root
    sudo chown -R $USER:$USER /var/www/mywebsite
  3. Now let’s change the file permission so that the owner can read, write, and execute the files while granting only read and execute permissions to groups and others:
    sudo chmod -R 755 /var/www/mywebsite
  4. Now lets create a simple html document to be served from our new virtual host. Create a document with the nano text editor called index.html in the /var/www/mywebsite/ directory:
    sudo nano /var/www/mywebsite/index.html.
  5. Once the new document opens, type the following text:
<html>
    <head>
        <title>My First Website</title>
    </head>
    <body>
        <h1>This is a sample document!</h1>
    </body>
</html>
  1. Save and close the file when you are finished. You can do this by pressing CTRL + X, then Y and ENTER.

NOTE: If you don’t want to use Nano, you can also do this in a single command

sudo curl https://cis106.com/assets/basic.html -o /var/www/mywebsite/index.html

setup virtual host 1

  1. Now we need to create a virtual host file so that this new content can be served. The default configuration is located in /etc/apache2/sites-available/000-default.conf However, we do not need to touch this file, we can instead create a new one as it is best practice. To create a new config file, we are going to use nano again:
    sudo nano /etc/apache2/sites-available/mywebsite.conf
  2. Add the following text to the domain config file:
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName mywebsite
    ServerAlias www.mywebsite
    DocumentRoot /var/www/mywebsite
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  1. Save and close the file when you are finished. You can do this by pressing CTRL + X, then Y and ENTER.
  2. Now enable the site with the following command:
    sudo a2ensite mywebsite.conf
  3. Now lets disable the default domain:
    sudo a2dissite 000-default.conf
  4. Before we can refresh the configuration, we need to add a configuration line to the apache2.conf file. Open the file in nano:
    sudo nano /etc/apache2/apache2.conf
  5. Add the following line at the end of the file:
    ServerName 127.0.0.1
  6. Save and close the file when you are finished. You can do this by pressing CTRL + X, then Y and ENTER.
  7. Now you can test the configuration for errors:
    sudo apache2ctl configtest
  8. The output of the command should look like this:
Syntax OK
  1. If there are no errors, restart Apache to apply the changes:
    sudo systemctl restart apache2
    Setup Virtual Host 2
  2. Now, if you open a web browser in your host computer and go the URL: http://ip.address.of.your.server/ your index.html document should load. sample site preview