How to Deploy an Azure Virtual Machine and connect Apache2 to it.
For beginners who are not yet familiar with the Azure portal, I'll help to simplify the process of deploying an Azure virtual machine (VM) and not just that, we'll also install the Apache2 server on the VM.
Step 1. You have to create a resource group. Search for resource group from the search bar.
Step 2. Click the create button
Step 3. Give the resource group a name, and choose a region, then review and create.
Step 4. After creating your resource group, you now need to create your virtual network. Search for VNet from the search bar and click on Virtual Networks.
Step 5. Click on create.
Step 6. Select the same resource group, give your virtual network a name and choose a region
After naming your virtual network, click the next button twice to get to the address space section where you should delete the default subnet section.
Review and create afterwards.
Step 7. Wait for Azure to validate your selection. Once passed, click create to continue.
Step 8. After creating your VNET, search for VNET from the search bar, click on Virtual Networks and click on the VNET you created. Your screen will be similar to the image below.
At the far left corner, click on settings to find subnets and click on it.
Click on subnet at the top from the image below to add a subnet.
Step 9. Name your subnet and click add.
Step 10. Now you've created a resource group, virtual network, and subnet. Let's move on to virtual machines. Search for virtual machines using the search bar.
Step 11. Following the images below, select your resource group, name your virtual machine, choose a region, select an availability zone.
Selsct Ubuntu Pro 24.04 LTS image (This is the latest as at the time of writing this article), choose a compute image size
Choose a username, selct ssh public key as authentication type
Click the next button twice to get to the networking section. Ensure the virtual network and subnet you created are selected, like in the image below, review and create.
Ensure you download your pem key after creating your vm.
Here's where you'll find your public IP address within your virtual machine.
Step 12. After creating your virtual machine, use the search bar to find your virtual machine and click on it. Once it opens, it will be similar to the image below.
What we want to do here is to add a port 80 HTTP inbound rule so that once we SSH into our virtual machine and install Apache2, we'll be able to paste our public IP in a browser and find Apache2 once it loads up.
So, click on networking on the far left.
Once you select the inbound port rule, the pop-up that you see below will appear, and you use the same parameters i used.
Step 13. Now that we've added port 80 to the 22 we added earlier, let's use GitBash to SSH into our virtual machine.
Firstly, run the pwd command to see where you are. If you're not in your local machine's home directory, use the cd ~ command to get into your home directory as I did in the image below.
Next, run the cd Downloads command to change the directory to your downloads folder. In my local machine, my downloads folder is named Downloads. Yours could be download or downloads, so take note.
Once you're in the downloads directory, run the chymod 400 chuks-vm_key.pem command. That's chymod 400 (and your pem key)
Next, run the ssh -i chuks-vm_key.pem chuks1@20.118.34.162 command to ssh into your virtual machine.
You have to replace my IP with the public IP of your virtual machine.
After logging in to the virtual machine, run the following command to update, upgrade and install Apache2 one after the other.
sudo apt update
sudo apt upgrade
sudo apt install apache2
To confirm that Apache2 has been installed, run the sudo systemctl status apache2
Step 15. Paste your virtual machine's public IP in a browser and load it to find Apache2.
Conclusion: These are all the steps to deploy an Azure virtual machine and, at the same time, install Apache2 on it.