I’ve set up my machine using Jeffrey Way’s guide and slightly modified the process to allow for XDebug remote debugging and now need to modify the provisioned machine to allow Codeception Db module to connect to the virtual machine MySQL database.
I’ve iterated over the information contained in this post by Jordan Eldredge to define repeatable steps.
The problem
The Codeception Db module will take care of resetting a test database to a known state from a dump file but will need a connection to the database to do so.
The virtual machine I’ve set up with Vagrant will not allow that out of the box and will need some configuration.
The virtual machine part of the solution
I will ssh into the vagrant machine with
vagrant ssh
and will edit the MySQL config file
vagrant@precise64:~$ vim /etc/mysql/my.cnf
and will comment the line dealing with the bind-address
value
mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
to tell MySQL to listen for connections from any IP address.
I will then register the root
remote user among the allowed ones
vagrant@precise64:~$ mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
The host machine part of the solution
I will now configure any suite using the Db
module to connect to the remote database
Db:
dsn: 'mysql:host=192.168.33.21;dbname=testDb'
user: 'root'
password: 'root'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: false
where 192.168.33.21
is the address of the virtual machine and user
and password
are the credentials set in the previous GRANT ...
statement.