When developing for the web, we need a local development environment. Virtual machines on Oracle VirtualBox are very convenient for creating local virtual servers for web development. Because you could have as many web dev servers (on different virtual machines) as you need.
1. Create an Ubuntu 22.04 (or 20.04) Virtual Machine
First, you need to install the [Oracle VirtualBox](https://www.virtualbox.org/wiki/Downloads).
When the VirtualBox software has been installed, you’ll need to create a new virtual machine. It’s a little bit less evident. So let’s consider it.
- To create a virtual machine, run the Oracle VirtualBox and click the button New
- In a window that opens, enter the virtual machine name, select the operating system, and click Continue
- On the next screen, set the RAM for the virtual machine. The default is 1GB. I usually set it to 2GB. But it depends on how much memory you have on the host machine and how much you are ready to spare. In any case, you’ll be able to increase or decrease the virtual machine RAM after the virtual machine has been created.
- Then you’ll need need to choose the Create the virtual hard disk now option which is the default
- Next, you’ll be asked to choose the virtual disk file type. I keep it at the default setting which is VDI
- Next, I always choose the hard disk to be Dynamically allocated. It allows me to set the disk size to some bigger value e.g. 100GB. But initially, the disk will be small (so the virtual machine will not take a lot of space on the host machine’s hard disk right away). And additional space will be allocated when necessary.
- And finally, set the virtual hard disk file size. I usually set the size to some bigger value, e.g. 60GB, since I always use a dynamically allocated disk (which means it will be small at first and will grow when necessary). You never know how much additional space you’ll need. So I find it convenient to set the disk size big enough.
- Now we need to install the Ubuntu operating system. So, you need to download the Ubuntu 22.04 Server iso image. You can do it here (or just Google for “ubuntu server download”).
After we have downloaded the iso image, select your newly created virtual machine in the left panel and click the button Settings
- In the window that opens, select the tab Storage. And add the iso file to the virtual machine optical drive
- Also, make sure that it is set for the virtual machine to boot from the CD-ROM first. It is done on the tab System of the same Settings window and this is the default boot sequence.
- Now when you start your virtual machine, the Ubuntu 22.04 installation from the virtual CD-ROM will start.
- Waitting…
2. Configure the Network
First check network enp1s0 in local machine
Virtualbox choose Bridge Adapter with name enp1s0
Start and Inside virtualbox els1 change the file /etc/netplan/00-installer-config.yaml
1
2
3
4
5
6
7
8
9
network:
ethernets:
enp0s3:
dhcp4: false
addresses: [192.168.18.10/24]
gateway4: 192.168.18.1
nameservers:
addresses: [8.8.8.8, 8.8.8.4]
version: 2
I used Google DNS servers here: 8.8.8.8, 8.8.8.4. You can use any DNS servers you wish instead of course. Refer What is a Gateway and What Does It Do?
Now to apply the changes, run in the terminal:
1
sudo netplan apply
If error
1
2
** (generate:1319): WARNING **: 02:50:58.543: `gateway4` has been deprecated, use default routes instead.
See the ‘Default routes’ section of the documentation for more details.
Let’s change and apply again
1
2
3
4
5
6
7
8
9
10
11
network:
version: 2
ethernets:
enp0s3:
dhcp4: false
addresses: [192.168.18.10/24]
nameservers:
addresses: [8.8.8.8, 8.8.8.4]
routes:
- to: default
via: 192.168.18.1
3. Start VM on background
Now. We can login with user from ssh outside
Otherwise we can login via root
1
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
Let’s try connect via SSH with root user



Comments powered by Disqus.