DEV Community

Cover image for Virtual Machine Setup and WordPress Installation Documentation
Victor Okonkwo
Victor Okonkwo

Posted on

Virtual Machine Setup and WordPress Installation Documentation

1. Launching a Virtual Machine Instance

Step 1: Log in to your Cloud Provider Console

  • Go to your chosen cloud service dashboard.
  • Select Create Instance or Launch Instance.

Step 2: Choose an OS Image

  • Select Ubuntu 22.04 or a similar version as the operating system.

Step 3: Configure the Instance

  • Choose the instance type (e.g., t2.micro for free-tier on AWS).
  • Select Storage (minimum 10GB).
  • Set Security Groups: Allow HTTP (port 80), HTTPS (port 443), and SSH (port 22).

Step 4: Launch Instance

  • After launching the instance, download the private key file for SSH access.

2. Accessing the Virtual Machine via SSH

Open your terminal or SSH client and connect to your instance with:

ssh -i path/to/your-key.pem ubuntu@<your-instance-public-ip>
Enter fullscreen mode Exit fullscreen mode

3. Installing WordPress

Install Prerequisites
Run the following commands to install Apache, MySQL, PHP, and required PHP modules:

sudo apt update && sudo apt upgrade -y
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php unzip wget -y
Enter fullscreen mode Exit fullscreen mode

Secure MySQL Installation

sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

Follow the prompts to secure MySQL.

Create WordPress Database

sudo mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Inside the MySQL prompt, create a database for WordPress:

CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Enter fullscreen mode Exit fullscreen mode

Download WordPress

wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress /var/www/html/
Enter fullscreen mode Exit fullscreen mode

Set Permissions for WordPress

sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
Enter fullscreen mode Exit fullscreen mode

Configure Apache to Serve WordPress
Update Apache configuration:

sudo nano /etc/apache2/sites-available/000-default.conf
Enter fullscreen mode Exit fullscreen mode

Change DocumentRoot /var/www/html to:

DocumentRoot /var/www/html/wordpress
Enter fullscreen mode Exit fullscreen mode

Disable the Default Apache Site:

sudo a2dissite 000-default.conf
Enter fullscreen mode Exit fullscreen mode

Enable Rewrite Module:

sudo a2enmod rewrite
Enter fullscreen mode Exit fullscreen mode

Restart Apache:

sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode

Complete WordPress Setup
Open your browser and navigate to http://<your-instance-public-ip>.
Follow the WordPress installation wizard.


4. Troubleshooting Steps

Issue 1: Apache Default Welcome Page Still Showing

  • Move WordPress Files to the Correct Directory Ensure the WordPress files are in /var/www/html/wordpress:
  sudo ls /var/www/html/wordpress
Enter fullscreen mode Exit fullscreen mode

If the directory is empty, re-download WordPress:

  cd /tmp
  wget https://wordpress.org/latest.tar.gz
  tar -xvzf latest.tar.gz
  sudo mv wordpress /var/www/html/
Enter fullscreen mode Exit fullscreen mode
  • Set WordPress as the Default Site Edit the Apache configuration to serve WordPress:
  sudo nano /etc/apache2/sites-available/000-default.conf
Enter fullscreen mode Exit fullscreen mode

Change DocumentRoot /var/www/html to:

  DocumentRoot /var/www/html/wordpress
Enter fullscreen mode Exit fullscreen mode
  • Disable Apache’s Default Welcome Page Disable the default welcome page to prevent it from overriding WordPress:
  sudo a2dissite 000-default.conf
Enter fullscreen mode Exit fullscreen mode
  • Enable Rewrite Module
  sudo a2enmod rewrite
Enter fullscreen mode Exit fullscreen mode
  • Restart Apache
  sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode
  • Check Permissions Make sure WordPress files have the correct permissions:
  sudo chown -R www-data:www-data /var/www/html/wordpress
  sudo chmod -R 755 /var/www/html/wordpress
Enter fullscreen mode Exit fullscreen mode
  • Access WordPress Setup Navigate to http://<your-instance-public-ip> in your browser and continue the WordPress installation.

Issue 2: Database Issues

  • Check if the database exists:
  SHOW DATABASES;
Enter fullscreen mode Exit fullscreen mode
  • Grant privileges on WordPress database:
  GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
  FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

Conclusion

You should now have a fully functional WordPress installation. If issues persist, refer to the troubleshooting steps provided to resolve common problems related to Apache configuration, WordPress file permissions, and database connections.

Tips:

  • Ensure your SSH key is correctly set up and you’re using the right permissions for secure access.
  • Regularly back up your WordPress site and database to avoid data loss.

Top comments (0)