Yiic Shell Using Ampps

Hi everyone,

I’m trying to use yiic shell and yiic migrate tools on my iMac but I seem to be running in to some difficulties. I think it may be because I am using AMPPS as my development server instead of having installed Apache/PHP/MySQL separately. For example, I can invoke the yiic shell but when I run:

echo Yii::app()->db->connectionString;

I get this lengthy error message:

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Applications/AMPPS/YiiRoot/framework/db/CDbConnection.php on line 423

exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/AMPPS/YiiRoot/framework/db/CDbConnection.php:381

Stack trace:

#0 /Applications/AMPPS/YiiRoot/framework/db/CDbConnection.php(330): CDbConnection->open()

#1 /Applications/AMPPS/YiiRoot/framework/db/CDbConnection.php(308): CDbConnection->setActive(true)

#2 /Applications/AMPPS/YiiRoot/framework/base/CModule.php(387): CDbConnection->init()

#3 /Applications/AMPPS/YiiRoot/framework/base/CModule.php(103): CModule->getComponent('db')

#4 /Applications/AMPPS/YiiRoot/framework/cli/commands/ShellCommand.php(131) : eval()'d code(1): CModule->__get('db')

#5 /Applications/AMPPS/YiiRoot/framework/cli/commands/ShellCommand.php(131): eval()

#6 /Applications/AMPPS/YiiRoot/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()

#7 /Applications/AMPPS/YiiRoot/framework/console/CConsoleCommandRunner.php(67): ShellCommand->run(Array)

#8 /Applications/AMPPS/YiiRoot/framework/console/CConsoleApplication.php(91): CConsoleCommandRunner->run(Array)

#9 /Applications/AMPPS/YiiRoot/framework/base/CApplication.php(169): CConsoleApplication->processRequest()

#10 /Applications/AMPPS/YiiRoot/framework/yiic.php(33): CApplication->run()

#11 /Applications/AMPPS/www/TrackStar/protected/yiic.php(7): require_once('/Applications/A...')

#12 /Applications/AMPPS/www/TrackStar/protected/yiic(4): require_once('/Applications/A...')

#13 {main}

I think it is perhaps because it is trying to connect via


which isn’t where my MySQL shell resides. I have configured my config/main.php and config/console.php to reflect:


    'connectionString' => 'mysql:host=localhost;dbname=trackstar',

    'emulatePrepare' => true,

    'username' => 'root',

    'password' => 'mysql',

    'charset' => 'utf8',


Can anyone help? I have the same problem when I try to use the migrations feature.

I’m sure about your specific set up, but I have run into a similar issue before on other stacks. My first place to explore would be Apache and PHP itself. Run a phpinfo and see if your PDO drivers are installed and that they are set up for MySQL, as this is what Yii uses to connect.

So, when you run your phpinfo, you should see a section for PDO. In that section, there should be a list of all the PDO db-specific drivers (i.e. MySQL, SQLite, PostgreSQL, etc). If you don’t see MySQL or PDO at all in your phpinfo, then you’ll need to alter your php.ini file and restart Apache.

Thanks for the reply.

I’ve checked phpinfo(); and everything seems to be OK (see image attached). Checking the /requirements folder from Yii also suggests that PDO is installed correctly. Could it perhaps be because that path to the MySQL sock is different to the one yiic is trying to use?


is what it says in the phpinfo() ?



Screen Shot 2013-01-10 at 23.14.45.png

I think I’ve figured this out. In order to get this working I had to change my /protected/config/main.php and /protected/config/console.php to read like so (highlighted the change in bold):


    'connectionString' => 'mysql:host=localhost;dbname=trackstar;unix_socket=/Applications/AMPPS/mysql/tmp/mysql.sock',

    'emulatePrepare' => true,

    'username' => 'root',

    'password' => 'mysql',

    'charset' => 'utf8',

    'tablePrefix' => 'tbl_',


I connect using this string

php /Applications/AMPPS/www/protected/yiic shell /Applications/AMPPS/www/protected/config/main.php

This is different to what I should be doing which is, as far as I know, be placing navigating to directory where the entry script of my application resides (/Applications/AMPPS/www/) and the executing the yiic tool. However, when I do this it just spews the contents of the entry script in to the shell then promptly exits.


Thanks, jacmoe. I was getting this error when trying to run a shell script to build an authentication hierarchy.

I don’t really understand why using localhost for the db connection in my main.php config worked for running the tutorial site but failed for the yiic shell, but your suggestion to use seems to have been just what the doctor ordered.