How to Install a WordPress Server on Hyper-V Using Apache (Step-by-Step Guide)

Introduction

In this guide, you’ll learn how to create a fully functional WordPress server inside a virtual machine using Hyper-V, the Apache web server, MySQL as the database, and PHP for processing. This is ideal for development, testing, or even hosting small websites internally.

Whether you’re setting this up for learning or to test plugins and themes, this article walks you through the entire setup from zero.


Prerequisites

  • A Windows machine with Hyper-V enabled
  • A downloaded ISO image of Ubuntu Server 22.04 LTS
  • Basic knowledge of Linux terminal commands
  • Internet connection on the VM

Step 1: Create a New Virtual Machine in Hyper-V

  1. Open Hyper-V Manager
  2. Click on “New” → “Virtual Machine…”
  3. Set the name (e.g., WordPressServer)
  4. Generation: Choose Generation 1 or Generation 2 (recommended if using UEFI boot)
  5. Assign memory: 2 GB minimum (more if available)
  6. Network: Attach to a virtual switch with internet access
  7. Hard disk: Create a new VHDX (minimum 20 GB)
  8. Install OS: Point to the downloaded Ubuntu ISO

Start the VM and proceed with Ubuntu installation.


Step 2: Install Ubuntu Server and Update Packages

In the Ubuntu installation screen:

  • Choose “Install Ubuntu Server”
  • Set timezone, language, keyboard
  • Configure a user (e.g., wordpressadmin)
  • Install OpenSSH server (optional but recommended)
  • Reboot when finished

After login:

sudo apt update && sudo apt upgrade -y

Step 3: Install Apache Web Server

sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2

To test, open the VM’s IP in your browser. You should see the Apache2 default page.


Step 4: Install MySQL Server

sudo apt install mysql-server -y
sudo mysql_secure_installation

When asked:

  • Set root password
  • Remove anonymous users: yes
  • Disallow remote root login: yes
  • Remove test database: yes

Step 5: Create a MySQL Database for WordPress

sudo mysql -u root -p

Inside MySQL prompt:

CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 6: Install PHP and Required Modules

sudo apt install php php-mysql libapache2-mod-php php-cli php-curl php-xml php-gd php-mbstring php-zip php-soap php-intl -y
sudo systemctl restart apache2

Step 7: Download and Install WordPress

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo cp -r wordpress/* /var/www/html/

Set proper permissions:

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Step 8: Configure Apache for WordPress

Create a new site config:

sudo nano /etc/apache2/sites-available/wordpress.conf

Paste the following:

<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html
ServerName yourdomain.com

<Directory /var/www/html>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable site and rewrite module:

sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 9: Finalize WordPress Setup via Browser

  1. Open your browser and go to the VM’s IP (e.g., http://192.168.1.100)
  2. Follow the WordPress web installer:
    • Choose language
    • Enter database info (use wordpress, wpuser, and the password)
    • Set site title, admin user, password, and email

Done!


Conclusion

You now have a fully working WordPress site running on a virtual machine inside Hyper-V, using Apache, MySQL, and PHP on Ubuntu. You can now install themes, plugins, and start creating content.

This setup is ideal for internal dev environments and learning how WordPress behaves in real infrastructure.


Optional Improvements

  • Configure SSL with Let’s Encrypt
  • Add UFW firewall rules
  • Use rsnapshot or rsync for local backups
  • Install phpMyAdmin
Edvaldo Guimrães Filho Avatar

Published by