I get a "command not found" error, though the script file is shown by "ls"
Solution 1
There are two problems:
The first is that you do not have the execute permission:
Add the permission for you with:
$ chmod u+x yiic
It gives u
, the user - you - the x
, execute permission.
The second, separate issue is about how you call the program, and how it is found.
Now you have the execute permission, but
$ yiic
will probably still give you a command not found
error.
That is because a command you run is searched for in the directories listed in the variable $PATH
- which does not include the current directory normally (and should not include it for security reasons).
But you can give a file name of the command to run, by including a directory path for the command file. The simplest variant of this is just using the current directory:
$ ./yiic
That should finally work!
If it works without the ./
in front too, then you have the current directory, .
, in your $PATH
- take a look at it:
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
(Oh, and then, there is the famous issue of using the file name test
for testing something... that's a pretty bad trap I would say - you are not the first person getting bitten by this one... )
Solution 2
You should to remove Win (CRLF) in first line;
If you open file in mcedit you will see:
!/usr/bin/env php^M
change it to
!/usr/bin/env php
Solution 3
The permissions on the file yiic
are not set so that it can be executed.
-rw-r----- 1 srv50213 srv50213 75 Aug 4 21:05 yiic
You can set it like so:
$ chmod u+x yiic
It should then look like this:
-rwxr----- 1 srv50213 srv50213 75 Aug 4 21:05 yiic
Why did test work?
You may think that you were running test
but in actuality you were running one of the nother commands called test
which are located here:
$ type -a test
test is a shell builtin
test is /usr/bin/test
test is /bin/test
This is assuming that you're using Bash as your shell, but the cause is likely to be the same, that you're running another version of test
.
To make sure you're running a command that's present in the current directory, it's always a good idea to prefix it with a dot slash, i.e.: ./test
. This forces the shell to run test
from the current location, rather than searching your $PATH
looking for one to run.
Related videos on Youtube
Igor Savinkin
I work in web scraping field. I do also tech copy writing and webscraping.pro blog editing. Welcome to directly contact me by email (igor [dot] savinkin [at] gmail [dot] com) for web scraping and data protection issues. Also contact me if you are interesting in copy writing or blog guest posting.
Updated on September 18, 2022Comments
-
Igor Savinkin over 1 year
I want to run
yii
console commands in shell. I runprotected/yiic
in the console, yet it fails, yielding-bash: yiic: command not found
What's the problem? See the shell commands and responses I have:
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]$
the
yiic
content:#!/usr/bin/env php <?php require_once(dirname(__FILE__).'/yiic.php');
the
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();
Update
I've changes the permissions as suggested, yet now when i run
./yiic
the result is : No such file or directory With./test
it works fine:-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]$
What's wrong?
Update 2
Actually yiic.php contains:
<?php // change the following paths if necessary $yiic=dirname(__FILE__).'/../../framework/yiic.php'; $config=dirname(__FILE__).'/config/main.php'; require_once($yiic);
where
/../../framework/yiic.php
is the path to the framework's yiic.php file exposed in main part of question. There is the yii.php file in the framework folder too.[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]$
Should i change mode (chmode) for yii.php and yiic.php in framework folder too?
Update 3
as suggested i ran
[srv50213@cl10-m protected]$ php yiic.php
and it issued php debug info: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/...')
DONE
Thank you to everyone. One problem was in there (as stated in debug info)
/home/srv50213/htdocs/framework/yiic.php(23)
with$config
-$app=Yii::createConsoleApplication($config);
. So I've changed the $config var in /home/srv50213/htdocs/doc/protected/yiic.php(5) from$config=dirname(__FILE__).'/config/main.php';
to$config=dirname(__FILE__).'/config/console.php';
and it has worked!!!Should i still run
php yiic.php
instead of./yiic
for example in cron command?-
MattBianco over 9 yearsTry the command
php yiic.php
from the folder that containsyiic.php
,yiic
, andtest
. -
Volker Siegel over 9 yearsDo you have two files with the same name
yiic
, in directoriesprotected
and inframework
? Same foryiic.php
? -
Igor Savinkin over 9 years@MattBianco, this command
php yiic.php
issued in real debug info - [srv50213@cl10-m protected]$ php yiic.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): -
slm over 9 years@IgorSavinkin - please edit your Q with this stuff. Keep adding update sections as you go along, rather than dump this in a comment.
-
Igor Savinkin over 9 years@Volker Siegel, it's true (the two files yiic.php in 2 diff dirs). Designed by yii framework though.
-
Igor Savinkin over 9 yearsi've edited my q. with update 3
-
Volker Siegel over 9 yearsFrom comparing to the code, the filename left out in last error line (
require_once('/home/srv50213/...')
) refers to the fileframework/yiic.php
.
-
-
Igor Savinkin over 9 yearsthank you, it really the thing you stated. But when i run
./yiic
the responce is: No such file or directory
. What's wrong? -
Volker Siegel over 9 yearsFor
./yiic
to work, you need to be in the same directrory. Otherwise, you need to use either a different relative path likefoo/yiic
if you are in your home directory and the file is in/home/igor/foo/yiic
, or an absolute path, like/home/igor/foo/yiic
. -
Igor Savinkin over 9 yearsbut php is trully installed on server. [srv50213@cl10-m protected]
$ command -v php
/usr/bin/php
how to resolve it? -
Igor Savinkin over 9 years@sim, thanks for the Why did test work? section.
-
slm over 9 years@IgorSavinkin - you're welcome. Thanks for the Q.
-
slm over 9 years@IgorSavinkin - you must if the
command -v php
returned a path tophp
. -
Igor Savinkin over 9 yearsseems there is no path to php.exe in $PATH - $ echo $PATH /usr/bin/env:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/web/users/srv50213/bin. How could i locate it and add path to php.exe into $PATH ?
-
slm over 9 years@IgorSavinkin -
$PATH
points a list of directories. The entries are separated by:
. The directory,/usr/bin
is where thephp
executable likely lives. -
Igor Savinkin over 9 yearsIt does, then why when i run
./yiic
i still have : No such file or directory ? -
slm over 9 years@IgorSavinkin - the No such file... is a result of something within the script, not the script itself. Based on the output it looks like a colon,
:
. -
Volker Siegel over 9 years@IgorSavinkin I think
yii.php
may be missing indeed - the linerequire_once(dirname(__FILE__).'/yii.php');
reads it from the current directory, but thels
does not show it. But it shows...
I just noticed - so check whether is is there. -
Igor Savinkin over 9 yearsi've checked the files and summed up in Update 2. Seems should be clear.
-
slm over 9 years@VolkerSiegel - you're likely right. Try
php yiic
. -
slm over 9 years@IgorSavinkin - try this pls:
php yiic
. -
anno over 7 yearsThat's a good one !