3
votes

I've already checked other questions and answers regarding my issue and nothing seems to help resolving it.

I'm using vagrant percise64 (ubuntu server 12.04) with lamp installed. On my host (desktop) I have myfinalproject dir containing extracted cakePHP version 2.3.5. I've set all that cakePHP required and on the generated page of cakePHP it says that "Cake is able to connect to the database."

When I try to bake a new Model/Controller or All I get the following error:

Welcome to CakePHP v2.3.5 Console
---------------------------------------------------------------
App : app
Path: /home/shahar/development/myfinalproject/app/
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q) 
> m
---------------------------------------------------------------
Bake Model
Path: /home/shahar/development/myfinalproject/app/Model/
---------------------------------------------------------------
Use Database Config: (default/test) 
[default] > default
Error: Database connection "Mysql" is missing, or could not be created.
#0 /home/shahar/development/myfinalproject/lib/Cake/Model/ConnectionManager.php(107): DboSource->__construct(Array)
#1 /home/shahar/development/myfinalproject/lib/Cake/Console/Command/Task/ModelTask.php(900): ConnectionManager::getDataSource('default')
#2 /home/shahar/development/myfinalproject/lib/Cake/Console/Command/Task/ModelTask.php(837): ModelTask->getAllTables(NULL)
#3 /home/shahar/development/myfinalproject/lib/Cake/Console/Command/Task/ModelTask.php(926): ModelTask->listAll(NULL)
#4 /home/shahar/development/myfinalproject/lib/Cake/Console/Command/Task/ModelTask.php(205): ModelTask->getName()
#5 /home/shahar/development/myfinalproject/lib/Cake/Console/Command/Task/ModelTask.php(93): ModelTask->_interactive()
#6 /home/shahar/development/myfinalproject/lib/Cake/Console/Command/BakeShell.php(108): ModelTask->execute()
#7 /home/shahar/development/myfinalproject/lib/Cake/Console/Shell.php(392): BakeShell->main()
#8 /home/shahar/development/myfinalproject/lib/Cake/Console/ShellDispatcher.php(200): Shell->runCommand(NULL, Array)
#9 /home/shahar/development/myfinalproject/lib/Cake/Console/ShellDispatcher.php(68): ShellDispatcher->dispatch()
#10 /home/shahar/development/myfinalproject/app/Console/cake.php(37): ShellDispatcher::run(Array)
#11 {main}

I've tried to run the bake command from my app dir (though i see the path is ok) and I got the same error. I've change in my database.php the localhost to 127.0.0.1 and still same error occurs.

What am I missing here?

Edit: Since people suggested i'll check PDO extension availability I did a tiny test. I used:

vagrant@precise64:/etc/php5/cli$ php -i | grep -i pdo
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini,
PDO
PDO support => enabled
PDO drivers => mysql
pdo_mysql
PDO Driver for MySQL => enabled
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
5
Are you running the CLI console from the vagrant vm (via ssh) or on the host machine?Tomdarkness
Running from HOST while PDO enabled on guest (vagrant box). Maybe I'm that stupid and this is why it doesn't work?Shahar Galukman
I had this problem and I was running the bake on the host machine. If you are using Vagrant, make sure you run the bake on the Vagrant box (ssh to it then bake).wenbert
This is what I end up doing eventually. There should be a way to bake from the Host machine though, I've yet found a solution to it. Of course it is same with Laravel artisian and I believe other frameworks CLI tools.Shahar Galukman

5 Answers

4
votes

Did you enabled pdo module for cli? I think that you can have different php.ini for cli / web (fpm).

3
votes

Just to help Ubuntu users out: I had the same error in my ubuntu 13.10 machine with the newest xampp downloaded directly from apachefriends. Try this:

Find the socket that mysqld creates for programs to connect to:

user@host /opt$ find . -name mysql.sock
/opt/lampp/var/mysql/mysql.sock

add it to your cakePHP database configuration file (cakePHP)/app/Config/database.php

'unix_socket' => '/opt/lampp/var/mysql/mysql.sock'

To me, this finally resulted in my cake commands being able to be executed without the "Error: Database connection "Mysql" is missing, or could not be created.".

1
votes

on apache start if you get a warning that says something along the lines of apache not resolving hostname, using 127.0.1.1.. this may cause problems later with cakephp. solution: sudo nano /etc/apache2/apache2.config , add the line: ServerName localhost

0
votes

Try to (re)install PHP MySQL support

sudo apt-get install php5-mysql
0
votes

For me it turned out to be that the server variable $_SERVER['HTTP_HOST'] was not available in the database.php config file so my specific config was not being set correctly when running in a Shell.

$_SERVER['HTTP_HOST'] is not available during Shell execution.