To set up a WordPress and phpMyAdmin environment using Vagrant, follow these steps:

Install Vagrant: Download and install Vagrant from the official website (https://www.vagrantup.com/). Make sure to also install the required virtualization software, such as VirtualBox or VMware.

Choose a Vagrant Box: Select a Vagrant box that suits your needs. For example, you can use the “bento/ubuntu-20.04” box, which provides an Ubuntu 20.04 base image. Initialize your Vagrant project by running the following command in your project directory:


vagrant init bento/ubuntu-20.04

Configure the Vagrantfile: Open the generated Vagrantfile in a text editor and modify it to include the necessary configurations. Here’s an example configuration that sets up a WordPress and phpMyAdmin environment:


Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-20.04"
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2 mysql-server php libapache2-mod-php php-mysql php-gd php-curl php-xml php-mbstring php-zip unzip
mysql -e "CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
mysql -e "GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password';"
a2enmod rewrite
systemctl restart apache2


cd /var/www/html
wget -c http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress/* .
rmdir wordpress
cp wp-config-sample.php wp-config.php
sed -i "s/database_name_here/wordpress/" wp-config.php
sed -i "s/username_here/wordpress/" wp-config.php
sed -i "s/password_here/password/" wp-config.php


wget -c https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
unzip phpMyAdmin-5.1.1-all-languages.zip
mv phpMyAdmin-5.1.1-all-languages phpmyadmin
SHELL


config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3306, host: 33060


config.vm.synced_folder ".", "/vagrant", disabled: true
end

This configuration installs Apache, MySQL, PHP, and phpMyAdmin, and sets up a WordPress installation.

Start the Vagrant environment: In the terminal, navigate to your project directory containing the Vagrantfile and run the following command to start the Vagrant environment:

vagrant up

Vagrant will download the base box if necessary and provision the virtual machine according to the configurations specified in the Vagrantfile.

Access WordPress and phpMyAdmin: Once the Vagrant environment is up and running, you can access WordPress by opening a web browser and visiting http://localhost:8080. To access phpMyAdmin, visit http://localhost:8080/phpmyadmin. Use the database credentials specified in the Vagrantfile to log in.

That’s it! You have set up a Vagrant environment with WordPress and phpMyAdmin. You can now develop and test your WordPress applications locally. Remember to customize the configuration based on your specific needs, such as database credentials and box selection.