Yii: command not found error using putty on VPS

Hi,

I am using yii 2 basic application template. I have a VPS server and have hosted. Everything is working fine. I am using RBAC for Authorization of users. It is also working fine. Now I want to run the command yii rbac/init using putty on my server. When I do that, it gives me foll error.’

]$ yii rbac/init
-bash: yii: command not found

How should I resolve this error?

You need to use ./yii rbac/init and make yii executable first using chmod +x yii

Hi,

I used php yii rbac/init, and it got executed successfully,

1 Like

To further your understanding, about executing shell commands:

The yii script is a PHP script, so you can invoke the php binary like you did to execute it, or:

That particular script ships with a “shebang”:

#!/usr/bin/env php   <- This line
<?php
/**
 * Yii console bootstrap file.
 *

It’s an indication for the shell you’re using, so that it knows how to execute that file.

That allow you to do : sh yii to have it executed through the PHP binary found in your environment.

And finally, if you make that file executable (chmod +x) then you can call ./yii instead of sh yii to execute it.

Hope this will clear some confusion :slight_smile:

1 Like