First of, I am pretty new to Vagrant. I have two Vagrant VMs to set up a Wordpress. This is my Vagrantfile:
Note: The synced folder “wordpress” in web1
contains the official files of the latest Wordpress files downloadable from their page using wget http://wordpress.org/latest.zip
and decompressing it afterwards.
Vagrant.configure("2") do |config|
config.vm.box = "generic/ubuntu2010"
config.vm.define :web1 do |web1|
web1.vm.provider :virtualbox do |vb|
vb.name = "web1"
vb.memory = "1024"
end
web1.vm.hostname = "web1"
web1.vm.network "forwarded_port", guest: 80, host: 1234
web1.vm.network "private_network", ip: "192.168.100.101", virtualbox__intnet: true
web1.vm.synced_folder "wordpress", "/var/www/html"
web1.vm.provision :shell, inline: <<-SHELL
apt-get update
apt-get install -y apache2 php php-mysql
SHELL
end
config.vm.define :db do |db|
db.vm.provider :virtualbox do |vb|
vb.name = "db"
vb.memory = "1024"
end
db.vm.hostname = "db"
db.vm.network "private_network", ip: "192.168.100.105", virtualbox__intnet: true
db.vm.provision :shell, inline: <<-SHELL
apt-get update
apt-get install -y mysql-server
mysql -u root -e "CREATE DATABASE wordpress;"
mysql -u root -e "CREATE USER 'wp_user'@'192.168.100.105' IDENTIFIED BY 'wp_pass';"
mysql -u root -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'192.168.100.105';"
SHELL
end
end
When I go to localhost:1234
and fill up the form with the DB data, I get “Error establishing a database connection”. I have tried a bunch of things and haven’t got any further. How can I fix this?
Thank you