socket problem

Hi Everybody!

I am learning the Yii framework via the Agile Book. Everything went great until page 186…

This is the case:

I have to create a RBAC authorization hierarchy via the yiic shell. This is the php command file for doing so:




<?php

class RbacCommand extends CConsoleCommand

{

   

    private $_authManager;

 

    public function getHelp()

	{

		return <<<EOD

USAGE

  rbac


DESCRIPTION

  This command generates an initial RBAC authorization hierarchy.


EOD;

	}


	

	/**

	 * Execute the action.

	 * @param array command line parameters specific for this command

	 */

	public function run($args)

	{

		//ensure that an authManager is defined as this is mandatory for creating an auth heirarchy

		if(($this->_authManager=Yii::app()->authManager)===null)

		{

		    echo "Error: an authorization manager, named 'authManager' must be con-figured to use this command.\n";

			echo "If you already added 'authManager' component in application con-figuration,\n";

			echo "please quit and re-enter the yiic shell.\n";

			return;

		}  

		

		//provide the oportunity for the use to abort the request

		echo "This command will create three roles: Owner, Member, and Reader and the following premissions:\n";

		echo "create, read, update and delete user\n";

		echo "create, read, update and delete project\n";

		echo "create, read, update and delete issue\n";

		echo "Would you like to continue? [Yes|No] ";

	   

	    //check the input from the user and continue if they indicated yes to the above question

	    if(!strncasecmp(trim(fgets(STDIN)),'y',1)) 

		{

		     //first we need to remove all operations, roles, child relationship and as-signments

			 $this->_authManager->clearAll();


			 //create the lowest level operations for users

			 $this->_authManager->createOperation("createUser","create a new user"); 

			 $this->_authManager->createOperation("readUser","read user profile in-formation"); 

			 $this->_authManager->createOperation("updateUser","update a users in-formation"); 

			 $this->_authManager->createOperation("deleteUser","remove a user from a project"); 


			 //create the lowest level operations for projects

			 $this->_authManager->createOperation("createProject","create a new project"); 

			 $this->_authManager->createOperation("readProject","read project in-formation"); 

	 		 $this->_authManager->createOperation("updateProject","update project information"); 

			 $this->_authManager->createOperation("deleteProject","delete a pro-ject"); 


			 //create the lowest level operations for issues

			 $this->_authManager->createOperation("createIssue","create a new is-sue"); 

			 $this->_authManager->createOperation("readIssue","read issue informa-tion"); 

			 $this->_authManager->createOperation("updateIssue","update issue in-formation"); 

			 $this->_authManager->createOperation("deleteIssue","delete an issue from a project");     


			 //create the reader role and add the appropriate permissions as children to this role

			 $role=$this->_authManager->createRole("reader"); 

			 $role->addChild("readUser");

			 $role->addChild("readProject"); 

			 $role->addChild("readIssue"); 


			 //create the member role, and add the appropriate permissions, as well as the reader role itself, as children

			 $role=$this->_authManager->createRole("member"); 

			 $role->addChild("reader"); 

			 $role->addChild("createIssue"); 

			 $role->addChild("updateIssue"); 

			 $role->addChild("deleteIssue"); 


			 //create the owner role, and add the appropriate permissions, as well as both the reader and member roles as children

			 $role=$this->_authManager->createRole("owner"); 

			 $role->addChild("reader"); 

			 $role->addChild("member");    

			 $role->addChild("createUser"); 

			 $role->addChild("updateUser"); 

			 $role->addChild("deleteUser");  

			 $role->addChild("createProject"); 

			 $role->addChild("updateProject"); 

			 $role->addChild("deleteProject");	

		

		     //provide a message indicating success

		     echo "Authorization hierarchy successfully generated.";

        } 

    }

}




once this is created I start the shell:


% YiiRoot/framework/yiic shell Yii Interactive Tool v1.1 (based on Yii v1.1.2) 

Please type 'help' for help. Type 'exit' to quit. >>

when I type "help" I see the rbac command between other commands, so that still works…

But from the moment I use this command, eg.


rbac help

, this is the error I get:




>> rbac help


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

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



I found this similar topic:

http://www.yiiframework.com/forum/index.php?/topic/6554-database-connection-issue/

But that didn’t work for me…tried everything.

I am using MAMP pro on a Mac. I also tried using XAMPP ->same problem.

It would be great if anyone could help me out!

Thanksssssssssssssss in advance

You don’t need to start a shell with yiic shell, but should instead try yiic rbac. According to your error message you might have more problems. But try it first and report back any issues.

Thanks for your answer.

I now get the available commands for yiic:


 ../../YiiRoot/framework/yiic rbac

Yii command runner (based on Yii v1.1.7)

Usage: ../../YiiRoot/framework/yiic <command-name> [parameters...]


The following commands are available:

 - message

 - migrate

 - shell

 - webapp


To see individual command help, use the following:

   ../../YiiRoot/framework/yiic help <command-name>

So I guess it is required to use the shell…

Try to use the yiic script that is in your application’s protected folder, not the one from the framework folder. And verify again that you put the RbacCommand.php in the right folder. It must be in protected/commands.

The yiic shell is another, special command that opens a shell - but the shell is deprecated now. What you have is not a shell command, but a “standard” yiic command. That’s why you have to call it with yiic rbac.

If it still doesn’t work, maybe you can help yourself by learning more about console commands, which you can do here:

http://www.yiiframew.../topics.console

I tried what you’ve said:

I get a different error, not the socket anymore…


yiic rbac

exception 'CException' with message 'Property "CConsoleApplication.authManager" is not defined.' in /path/to/YiiRoot/framework/base/CComponent.php:131

Could this be simpler to solve?

You’re getting closer: The message tells you, that you don’t have a authManager component configured (see config/console.php). Since i didn’t read the book, i can’t tell, if you missed a step - but i’m quite sure, Jeff mentioned it somewhere. And i remember, this issue already came up several times. Try searching in this subsection:

http://www.yiiframework.com/forum/index.php?/forum/38-yii-book-discussions/

BTW this is easy to solve - but you should find out yourself how to do it ;)

I added the authManager component to my console.php config file instead of the main.php config file. Again the same socket error. So I am back to the start.

I’ve done the steps three times (from the book), so I would be surprised that I missed a step…

I appreciate your effort for helping me!!

What’s your current error messag? Is it the PDO error again? Then you’re again a step further: authManager seems to work and tries to access your DB. But something with your database connection is wrong. Maybe you didn’t configure your db in console.php?

yes, again it is the PDO. Yes I also configured db:

console.php:


<?php


// This is the configuration for yiic console application.

// Any writable CConsoleApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'My Console Application',

	// application components

	'components'=>array(

		/*

		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		*/

		// uncomment the following to use a MySQL database

		

		'db'=>array(

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

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		'authManager'=>array(

			'class'=>'CDbAuthManager',

			'connectionID'=>'db',

		),

		

	),

);

PHP Error[2]: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)

Ah, the old MySQL socket problem. Try this:

http://www.yiiframework.com/forum/index.php?/topic/6554-database-connection-issue/page__view__findpost__p__33536

Sorry, you already mentioned that topic. But now you’re some steps further, so maybe try again.

Alrightyyyyyyy

now it did work when adding: unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock to my db settings in console.php!

Finally!!!!!!!!

Thanks for your patience and help!

yihaaaaaa

I’m reading the Web Application Development with Yii and PHP 2nd Ed. In Ch. 4 p.90 I had an issue running the $./yiic migrate command.

The solution was:




// uncomment the following to use a MySQL database

                'db'=>array(

                       //chage host from localhost to 127.0.0.1

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

                        'emulatePrepare' => true,

                        'username' => 'admin',

                        'password' => '',

                        'charset' => 'utf8',

                ),



Instead of using localhost, use the ip address instead.

Dev Stack: XAMPP on MAC OS X

Yii 1.1.13