How to use database on Vagrant for testing with Codeception

时光毁灭记忆、已成空白 提交于 2020-01-06 10:39:51

问题


I use Vagrant and Codception, but when i want to test application localy, I must do it on LAMP (or something like that) server. How can I use database on Vagrant?


回答1:


All you need is just to setup access to your mysql server that runs on the guest machine (vagrant box) from the host and then to set appropriate database DNS in your codeception.yml config.

Here is some general instructions:

1) Allow your vagrant's mysql server listen all interfaces ssh to your box by setting 'bind-address' option in mysql's my.cnf config and change it's value to 0.0.0.0

2) Grant appropriate privileges to mysql user that will be used to connect to database from the host. You can do this running following SQL commands using mysql client

USE mysql;  
GRANT ALL ON *.* to root@'192.168.0.1' IDENTIFIED BY 'mypass';  
FLUSH PRIVILEGES;

where root and mypass - your database user which will be used from codeception to connect to database and its password and 192.168.0.1 - the ip of the host (read how get host's ip for your gest here)

3) Restart vagrant's mysql server

4) To test connection to vagrant's mysql from the host run

mysql -h 192.168.33.10 -P 3306  -u root -p

(Here 192.168.33.10 - ip of my running vagrant box)

5) Set up DNS in codeception.yml file, e.g.

modules:
    config:
        Db:
            dsn: 'mysql:host=192.168.33.10;dbname=MyDB'
            user: 'root'
            password: 'mypass'


来源:https://stackoverflow.com/questions/22481354/how-to-use-database-on-vagrant-for-testing-with-codeception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!