Setting Up a Personal Apache Server on a Virtual Machine (VM) Not Connected Directly to the Internet
In this article, we will discuss the steps required to set up a personal Apache server on a virtual machine (VM) that is not connected directly to the internet. The VM in this example runs Ubuntu Server 24.04, while the host laptop runs Ubuntu Desktop 24.04. This setup is ideal for educational purposes, allowing you to learn and experiment with Apache server administration in a controlled environment.
Prerequisites
Before we begin, make sure you have the following prerequisites:
- A laptop running Ubuntu Desktop 24.04
- VirtualBox installed on the laptop
- An Ubuntu Server 24.04 ISO file
Step 1: Create a Virtual Machine
Launch VirtualBox and create a new virtual machine with the following specifications:
- Name: Apache Server
- Type: Linux
- Version: Ubuntu (64-bit)
- Memory size: 1024 MB
- Hard drive: Create a new virtual hard drive now
- Hard drive file type: VDI (VirtualBox Disk Image)
- Storage on physical hard drive: Dynamically allocated
- File size: 8 GB
Step 2: Install Ubuntu Server on the Virtual Machine
Start the virtual machine and insert the Ubuntu Server 24.04 ISO file. Follow the on-screen instructions to complete the installation. Make sure to select the OpenSSH server option during the installation process.
Step 3: Connect to the Virtual Machine Using SSH
Once the installation is complete, shut down the virtual machine and remove the ISO file. Start the virtual machine again and use SSH to connect to it from the host laptop. The default username and password are ubuntu and ubuntu, respectively.
Step 4: Install Apache, MySQL, and PHP (LAMP Stack)
Once connected to the virtual machine, run the following commands to install the LAMP stack:
sudo apt update
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
During the installation process, you will be prompted to set a root password for MySQL. Make sure to remember this password.
Step 5: Test the Apache Installation
Once the LAMP stack is installed, test the Apache installation by opening a web browser on the host laptop and navigating to http://localhost. You should see the default Apache web page.
Step 6: Secure MySQL
Secure the MySQL installation by running the following command:
sudo mysql_secure_installation
Follow the on-screen instructions to set the root password, remove anonymous users, and disable remote root login.
Step 7: Create a Virtual Host
Create a new virtual host by creating a new configuration file in the /etc/apache2/sites-available/ directory. For example, to create a virtual host for the domain example.com, create a new file called example.com.conf with the following contents:
<VirtualHost *:80>
ServerName example.com
ServerAdmin [email protected]
DocumentRoot /var/www/example.com
ErrorLog ${APACHE\_LOG\_DIR}/error.log
CustomLog ${APACHE\_LOG\_DIR}/access.log combined
</VirtualHost>
Create the corresponding directory for the virtual host by running the following command:
sudo mkdir /var/www/example.com
Set the ownership and permissions for the virtual host directory:
sudo chown -R $
```bash
```