Reputation: 902
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
Upvotes: 3
Views: 11476
Reputation: 41
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.
Upvotes: 0
Reputation: 64
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
Upvotes: 1
Reputation: 652
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.".
Upvotes: 3
Reputation: 611
Try to (re)install PHP MySQL support
sudo apt-get install php5-mysql
Upvotes: 0
Reputation: 4142
Did you enabled pdo module for cli? I think that you can have different php.ini for cli / web (fpm).
Upvotes: 4