In this guide, we'll show you how to install WordPress on a Linux Vagrant virtual machine step-by-step. Vagrant is a useful tool that lets you create and manage virtual environments, making it easy to test your web applications locally before deploying them to a live server.
Before we begin, make sure you have the following things ready:
A computer running Linux (Ubuntu, Fedora, etc.).
VirtualBox installed on your system to create the virtual machine.
Vagrant installed on your machine to handle the virtual environment setup.
Step 1: Install VirtualBox and Vagrant
If you don't have VirtualBox and Vagrant installed, download and install the latest versions from their official websites:
Step 2: Create a New Directory
Open your terminal and create a new directory where we'll store the Vagrant configuration files. For example, let's call it "wordpress-vagrant."
mkdir wordpress-vagrant cd wordpress-vagrant
Step 3: Initialize Vagrant Environment
Next, initialize our Vagrant environment by creating a new Vagrantfile:
vagrant init ubuntu/bionic64
This will create a Vagrantfile in your current directory, which serves as the configuration file for your virtual machine.
Step 4: Configure Vagrantfile
Open the Vagrantfile using a text editor (like nano, vim, or VSCode). Find the line that looks like this:
# config.vm.box = "ubuntu/bionic64"
Uncomment the line by removing the "#" at the beginning and save the file. This line specifies the base box image to use for the virtual machine, which in this case is Ubuntu 18.04 (bionic64).
Step 5: Start the Virtual Machine
To start the virtual machine, run the following command:
Vagrant will download the specified base box image if it's not already on your machine. This might take a few minutes, depending on your internet speed.
Step 6: SSH into the Virtual Machine
Once the virtual machine is up and running, you can SSH into it using the following command:
Congratulations! You are now inside your Linux Vagrant virtual machine.
Step 7: Install LAMP Stack (Linux, Apache, MySQL, PHP)
To set up WordPress, we need to install the LAMP stack in the virtual machine. Execute the following commands one by one:
sudo apt update sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
During the MySQL installation, you'll be prompted to set a root password. Make sure to remember this password as you'll need it later.
Step 8: Download and Install WordPress
Now that the LAMP stack is set up, it's time to install WordPress. Follow these steps:
cd /var/www/html sudo rm index.html sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo mv wordpress/* . sudo rmdir wordpress sudo rm latest.tar.gz
Step 9: Configure MySQL Database for WordPress
Before configuring WordPress, create a new MySQL database and user for it:
mysql -u root -p
Enter your MySQL root password and then execute the following SQL commands:
CREATE DATABASE wordpress_db; CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_password_here'; GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
Replace "your_password_here" with a strong password for the WordPress database user.
Step 10: Configure WordPress
Open your browser and go to http://localhost:8080/. The WordPress setup page should appear. Select your language and proceed.
On the next page, enter the following information:
Database Name: wordpress_db
Password: (the password you set for the database user)
Database Host: localhost
Table Prefix: (leave it as is, or change if desired)
Complete the WordPress installation process by providing site information, username, and password for your WordPress admin account.
Step 11: Access Your WordPress Website
After completing the setup, you can access your WordPress website by visiting http://localhost:8080/ in your browser.
Congratulations! You have successfully set up a WordPress website on a Linux Vagrant virtual machine using VirtualBox and Vagrant. This local environment allows you to test and develop your WordPress projects without affecting your live server. Happy coding!
Did you find this article valuable?
Support DevOps 0 to 1 by becoming a sponsor. Any amount is appreciated!