3

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
Shahar Galukman
  • 882
  • 3
  • 15
  • 35
  • 2
    Are you running the CLI console from the vagrant vm (via ssh) or on the host machine? – Tomdarkness May 24 '13 at 01:34
  • 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 May 24 '13 at 07:02
  • 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 Sep 17 '13 at 21:52
  • 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 Sep 19 '13 at 05:37

5 Answers5

4

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

Matheno
  • 4,112
  • 6
  • 36
  • 53
  • Could you please reference me to how I do it? As I recall PDO should be already enabled on php.ini with php version 5.3.x but I might be mistaken here. – Shahar Galukman May 22 '13 at 09:47
  • It seems PDO is enabled for mysql vagrant@precise64:~$ php --ri pdo PDO PDO support => enabled PDO drivers => mysql – Shahar Galukman May 22 '13 at 09:48
  • uncomment extension="pdo_mysql.so" under /opt/lampp/etc/php.ini – MuntingInsekto May 22 '13 at 09:49
  • I don't have lamp folder under opt – Shahar Galukman May 22 '13 at 09:54
  • just look for the php.ini file then uncomment extension="pdo_mysql.so" – MuntingInsekto May 22 '13 at 10:21
  • Use your terminal type in 'locate php.ini', you will be able to see different php.ini in your system. Most probably you will have the php.ini file here /etc/php5/apache2/php.ini. Make sure you also do the same for php cli /etc/php5/cli/php.ini – harikrish May 22 '13 at 10:47
  • Since I enable PDO on my server and tried to use the CLI on my client (desktop) it wasn't working, yeah dumb me. Please update your answer to be a real answer and not a comment so I can accept it. – Shahar Galukman May 24 '13 at 11:50
3

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.".

FaustoW
  • 632
  • 7
  • 15
1

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

Try to (re)install PHP MySQL support

sudo apt-get install php5-mysql
0

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.