Question

OSX machine running MAMP. CakePHP 2.2.1 installed and configured properly (meaning that I have all green bars when I browse to the Index.php file, I have completed the Blogs tutorial and am working on my second app with which scaffolding is up and running). Now I am trying to Bake for the first time.

Per the cookbook (and others), I installed a fresh copy of cake into a directory (my users directory) and then put the path variable in my .bash_profile file export PATH="$PATH:/Users/p_scott/cake221/app/Console" after which I was able to go into Terminal, type cake and have the console come up. You can see that up to that point, I was invoking the console from the app directory.

I first tried running cake bake from the terminal using the -app parameter and designating the path to my practice apps. The first time I did this, I got the following

    Welcome to CakePHP v2.2.1 Console
    -------------
    App : app
    Path: /Applications/MAMP/htdocs/blog/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)
    > c
    -------------------- 
    Bake Controller
    Path: /Applications/MAMP/htdocs/blog/app/Controller/
    -------------------- 
    \Use Database Config: (default/test)
    [default] >

No matter what I put in for the database (if I leave it blank, it asks me again), but any answer gives me the following error:

    Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in    [/Users/p_scott/cake221/lib/Cake/Model/Datasource/Database/Mysql.php, line 149]

    Error: Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
    #0 /Users/p_scott/cake221/lib/Cake/Model/Datasource/DboSource.php(260): Mysql->connect()
    #1 /Users/p_scott/cake221/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)
    #2 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ModelTask.php(906): ConnectionManager::getDataSource('default')
    #3 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(396): ModelTask->getAllTables('default')
    #4 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(419): ControllerTask->listAll(NULL)
    #5 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(136): ControllerTask->getName()
    #6 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(61): ControllerTask->_interactive()
    #7 /Users/p_scott/cake221/lib/Cake/Console/Command/BakeShell.php(113): ControllerTask->execute()
    #8 /Users/p_scott/cake221/lib/Cake/Console/Shell.php(393): BakeShell->main()
    #9 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(201): Shell->runCommand(NULL, Array)
    #10 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
    #11 /Users/p_scott/cake221/app/Console/cake.php(33): ShellDispatcher::run(Array)
    #12 {main}

Once I started getting this error, I tried navigating in terminal to the <cake install dir>/app/Console folder and the <different instance of cake install dir>/app/Console folder to try the console from within my app/s. I either get the same errors or it asks me different questions, like:

    What is the path to the project you want to bake?  
    [/Users/p_scott/myapp] > /Applications/MAMP/htdocs/history/app 
    What is the path to the directory layout you wish to copy?  
    [/Applications/MAMP/htdocs/history/lib/Cake/Console/Templates/skel] > 

PHP CLI is installed and it appears to be working

    PHP 5.3.8 (cli) (built: Dec  5 2011 21:24:09) 
    Copyright (c) 1997-2011 The PHP Group
     Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

My PDO support appears to be enabled. In terminal I typed:

    php --ri pdo
    PDO
    PDO support => enabled
    PDO drivers => mysql, sqlite, sqlite2

I don't have a php.ini file in Apache (because I am on a Mac), but the one in the PHP 5.36 directory, I have the following extensions enabled:

    extension=imap.so
    extension=yaz.so
    extension=mcrypt.so
    extension=gettext.so
    extension=pgsql.so
    extension=pdo_pgsql.so
    extension=pdo_mysql.so

After taking a break, I found an article (http://www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/) that talks about a change of console location in 2.0. I should try using it from that location (<cake installed dir>/lib/Cake/Console ). Once I tried this, I either got the questions about what layout I wanted to use or... ONCE, I was able to get the bake application to ask me to create a database configuration. I went through the steps and it pooped out this error at the end:

Fatal error: Class 'DATABASE_CONFIG' not found in /Applications/MAMP/htdocs/history/lib/Cake/Console/Command/Task/DbConfigTask.php on line 264

Which leads me to one more piece of info. This is my default DB configuration in the <cake installation dir>/history/app/Config/database.php file.

    class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'cakeHistoryUser',
    'password' => 'cakeHistoryPassword',
    'database' => 'cake_history',
    'prefix' => '',
    //'encoding' => 'utf8',
   );

Before posting this question (and all of this information), I spend some quality time out here and it seems like most of my issues are or CLI related but I just don't see where I need to change something and hours and hours later, I need some help.

Help me Obi Wan, you are my only hope

Was it helpful?

Solution

The problem is you are trying to interact with the database via the command line, however the PHP-CLI is a different install than the one proveided by MAMP so it doesn't know about the database server.

Try changing localhost to 127.0.0.1 in your app/Config/database.php file and that should do the trick.

OTHER TIPS

Something like this happened to me, and the easiest way I found to make it work which I don't see here is changing localhost to 127.0.0.1 and adding the port number at the end, e.g., MAMP uses port number 8899, so:

"mysql:host=127.0.0.1:8889"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top