Question :
I’m learning to work with the vagrant , I’ve already created VirtualMachine
, I made the provisioning, the project ran perfectly.
But when I enter via ssh in VirtualMachine
to run a script php , which runs via shell, is experiencing a connection error with the .
“cdbconnection failed to open the db connection: could not find driver”
I use the framework yii . Another thing is when I run the vagrant reload I lose access to the web server remotely.
Answer :
The error message is clear: the MySQL database access driver could not be found.
The extension was probably not enabled. Check out your php.ini
. On Windows, something like:
extension_dir="C:/php5/ext/"
extension=php_mysql.dll
On other systems, something like:
extension_dir="/usr/lib/php/modules/"
extension=mysql.so
A Windows user said that Yii requires extension=php_pdo_mysql.dll
(that is, ” php_pdo_mysql ” instead of ” php_mysql “).
It is also important to remember restart PHP and / or Apache after making changes to the configuration files.
Sources:
Your DSN shows that you are trying to use the MySQL driver and the error indicates that the driver is unavailable.
Verify that the extension is installed.
In Ubuntu / Debian you can do the following to verify that it is installed
dpkg --get-selections | grep php5-mysql
If it is not, you can install it as well
sudo apt-get install php5-mysql
Then restart apache for the new settings to take effect.
sudo /etc/init.d/apache2 restart
If already installed check which host MySQL is accepting connections to. Run
sudo nano /etc/mysql/my.cnf
Change bind-address
to 0.0.0.0
to listen for connections from any IP.
bind-address = 0.0.0.0
Give connection permission for all IPs
mysql -u root -p
At the MySQL prompt type
use mysql
// Caso o root não possua senha use
GRANT ALL PRIVILEGES ON *.* TO root@'%'
// Se tiver senha use
GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'senha';
FLUSH PRIVILEGES;
exit
Restart MySQL
sudo /etc/init.d/mysql restart