Eu quero executar yii
comandos do console no shell.
Eu corro protected/yiic
no console, mas ele falha, gerando -bash: yiic: command not found
Qual é o problema?
Veja os comandos e respostas da shell que tenho:
ls -l
...
-rw-r----- 1 srv50213 srv50213 94 Aug 21 09:26 test
-rw-r----- 1 srv50213 srv50213 75 Aug 4 21:05 yiic
-rw-r----- 1 srv50213 srv50213 395 Aug 4 21:05 yiic.bat
-rw-r----- 1 srv50213 srv50213 178 Aug 4 21:05 yiic.php
[srv50213@cl10-m protected]$ test
[srv50213@cl10-m protected]$ test
[srv50213@cl10-m protected]$ yiic
-bash: yiic: command not found
[srv50213@cl10-m protected]$ yiic.php
-bash: yiic.php: command not found
[srv50213@cl10-m protected]$
o yiic
content:
#!/usr/bin/env php
<?php
require_once(dirname(__FILE__).'/yiic.php');
o yiic.php
content:
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('YII_DEBUG') or define('YII_DEBUG',true);
require_once(dirname(__FILE__).'/yii.php');
if(isset($config))
{
$app=Yii::createConsoleApplication($config);
$app->commandRunner->addCommands(YII_PATH.'/cli/commands');
}
else
$app=Yii::createConsoleApplication(array('basePath'=>dirname(__FILE__).'/cli'));
$env=@getenv('YII_CONSOLE_COMMANDS');
if(!empty($env))
$app->commandRunner->addCommands($env);
$app->run();
Atualizar
Alterei as permissões conforme sugerido, mas agora, quando corro
./yiic
o resultado é : nenhum arquivo ou diretório desse tipo
Com ./test
funciona bem:
-rwxr----- 1 srv50213 srv50213 94 Aug 21 11:33 test
-rwxr-xr-x 1 srv50213 srv50213 75 Aug 4 21:05 yiic
-rw-r----- 1 srv50213 srv50213 178 Aug 4 21:05 yiic.php
[srv50213@cl10-m protected]$ test
[srv50213@cl10-m protected]$ ./test
test OK
[srv50213@cl10-m protected]$ ./yiic
: No such file or directory
[srv50213@cl10-m protected]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/web/users/srv50213/bin
[srv50213@cl10-m protected]$
O que há de errado?
Atualização 2
Na verdade, yiic.php contém:
<?php
// change the following paths if necessary
$yiic=dirname(__FILE__).'/../../framework/yiic.php';
$config=dirname(__FILE__).'/config/main.php';
require_once($yiic);
onde /../../framework/yiic.php
é o caminho para o arquivo yiic.php do framework exposto na parte principal da questão. Também existe o arquivo yii.php na pasta do framework.
[srv50213@cl10-m protected]$ cd ..
[srv50213@cl10-m doc]$ cd ..
[srv50213@cl10-m htdocs]$ cd framework
[srv50213@cl10-m framework]$ ls -l
total 432
drwxr-s--- 2 srv50213 srv50213 4096 Jul 16 23:37 base
drwxr-s--- 3 srv50213 srv50213 4096 Jul 16 23:37 caching
drwxr-s--- 5 srv50213 srv50213 4096 Jul 16 23:37 cli
drwxr-s--- 2 srv50213 srv50213 4096 Jul 16 23:37 collections
drwxr-s--- 2 srv50213 srv50213 4096 Jul 16 23:37 console
drwxr-s--- 4 srv50213 srv50213 4096 Jul 16 23:38 db
drwxr-s--- 9 srv50213 srv50213 4096 Jul 16 23:38 gii
drwxr-s--- 4 srv50213 srv50213 4096 Jul 16 23:41 i18n
drwxr-s--- 2 srv50213 srv50213 4096 Jul 16 23:41 logging
drwxr-s--- 11 srv50213 srv50213 4096 Jul 16 23:45 web
-rw-r----- 1 srv50213 srv50213 37100 Jul 16 23:37 YiiBase.php
-rw-r----- 1 srv50213 srv50213 358 Jul 16 23:37 yiic
-rw-r----- 1 srv50213 srv50213 577 Jul 16 23:37 yiic.bat
-rw-r----- 1 srv50213 srv50213 834 Aug 21 13:05 yiic.php
-rw-r----- 1 srv50213 srv50213 304900 Jul 16 23:37 yiilite.php
-rw-r----- 1 srv50213 srv50213 638 Jul 16 23:37 yii.php
-rw-r----- 1 srv50213 srv50213 175 Jul 16 23:37 yii-powered.png
-rw-r----- 1 srv50213 srv50213 694 Jul 16 23:37 yiit.php
drwxr-s--- 4 srv50213 srv50213 4096 Jul 16 23:45 zii
[srv50213@cl10-m framework]$
Devo mudar o modo (chmode) para yii.php e yiic.php na pasta do framework também?
Atualização 3
como sugerido eu corri [srv50213@cl10-m protected]$ php yiic.php
e ele emitiu informações de depuração do php:
exception 'CException' with message 'Property "CConsoleApplication.defaultController" is not defined.' in /home/srv50213/htdocs/framework/base/CComponent.php:173
Stack trace:
#0 /home/srv50213/htdocs/framework/base/CModule.php(515): CComponent->__set('defaultControll...', 'site')
#1 /home/srv50213/htdocs/framework/base/CApplication.php(161): CModule->configure(Array)
#2 /home/srv50213/htdocs/framework/YiiBase.php(125): CApplication->__construct('/home/srv50213/...')
#3 /home/srv50213/htdocs/framework/YiiBase.php(113): YiiBase::createApplication('CConsoleApplica...', '/home/srv50213/...')
#4 /home/srv50213/htdocs/framework/yiic.php(23): YiiBase::createConsoleApplication('/home/srv50213/...')
#5 /home/srv50213/htdocs/doc/protected/yiic.php(7): require_once('/home/srv50213/...')
FEITO
Obrigado a todos. Um problema estava lá (conforme informado nas informações de depuração) /home/srv50213/htdocs/framework/yiic.php(23)
com $config
- $app=Yii::createConsoleApplication($config);
.
Então eu mudei o $ config var em /home/srv50213/htdocs/doc/protected/yiic.php (5) de $config=dirname(__FILE__).'/config/main.php';
para
$config=dirname(__FILE__).'/config/console.php';
e funcionou !!!
Devo ainda executar php yiic.php
em vez de ./yiic
, por exemplo, no comando cron?