Recebi a mensagem de "Connection refused" ao final do vídeo 5.06. Revisei os códigos em não encontrei nenhum erro.
VAGRANTFILE
$script_mysql = <<-SCRIPT
echo ----------------------------UPDATE APT-GET
apt-get update && \
echo ----------------------------INSTALL MYSQL
apt-get install -y mysql-server-5.7 && \
echo ----------------------------CONFIG MYSQL
mysql -e "create user 'phpuser'@'%' identified by 'pass';"
echo ----------------------------END SCRIPT
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.define "mysqldb" do |mysql|
#-----------------------INTERFACE DE REDE
#mysql.vm.network "private_network", type: "dhcp"
mysql.vm.network "public_network", ip: "192.168.0.100"
#---------------------COMANDOS BASH/SHELL
mysql.vm.provision "shell",
inline: "cat /configs/id_bionic.pub >> .ssh/authorized_keys" # incrementa
mysql.vm.provision "shell", inline: $script_mysql
mysql.vm.provision "shell",
inline: "cat /configs/mysqld.cnf > /etc/mysql/mysql.conf.d/mysqld.cnf" #sobrescreve
mysql.vm.provision "shell", inline: "service mysql restart"
#-----------------SINCRONIZAÇÃO E ACESSO A PASTAS HOST-GUEST
mysql.vm.synced_folder "./configs", "/configs" # pasta VM, pasta host - A Referência é a pasta do vagrantfile
mysql.vm.synced_folder ".", "/vagrant", disabled: true #Evita acesso ao vagrantfile
end
config.vm.define "phpweb" do |phpweb|
phpweb.vm.network "forwarded_port", guest: 8888, host: 8888
phpweb.vm.network "public_network", ip: "192.168.0.101"
phpweb.vm.provision "shell",
inline: "apt-get update && apt-get install -y puppet"
phpweb.vm.provision "puppet" do |puppet|
puppet.manifests_path = "./configs/manifests"
puppet.manifest_file = "phpweb.pp"
end
end
end
PHPWEB.PP
exec { 'apt-update':
command => '/usr/bin/apt-get update'
}
package { ['php7.2' ,'php7.2-mysql'] :
require => Exec['apt-update'],
ensure => installed,
}
exec { 'run-php7':
require => Package['php7.2'],
command => '/usr/bin/php -S 0.0.0.0:8888 -t /vagrant/src &'
}
INDEX.PHP
<?php
echo "Testando conexao <br /> <br />";
$servername = "192.168.0.101";
$username = "phpuser";
$password = "pass";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Conexão falhou: " . $conn->connect_error);
}
echo "Connetado com sucesso";
?>