0

I am trying to create new yii application on Ubuntu by calling:

sudo yii-project/framework/yiic webapp yiidemo

from my htdocs dicectory(XAMPP). The message I get is:

/usr/bin/env: php: No such file or directory

PHP is installed though. 'php -v' yelds:

PHP 5.5.11 (cli) (built: Apr  9 2014 14:29:14) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

My PATH looks like that('echo $PATH'):

/home/alan/home/alan/netbeans-8.0/bin/netbeans/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/lampp/bin

'php' seems to be in /opt/lampp/bin so the last entry.

Any advice on how to make it work and get rid of the error would be greatly appreciated :).

Alan
  • 1,322
  • 1
  • 21
  • 36
  • Could your `sudo` be [changing PATH on you, like it's sometimes known to on Ubuntu](http://stackoverflow.com/questions/257616/sudo-changes-path-why)? – Matt Gibson Apr 29 '14 at 15:11
  • In my case 'sudo echo $PATH' returns the same string as 'echo $PATH'. – Alan Apr 29 '14 at 15:14
  • Out of interest, what happens if you try `sudo php yii-project/framework/yiic webapp yiidemo`? – Matt Gibson Apr 29 '14 at 19:17
  • Good bet :). `sudo: php: Command not found`. I get the same for `sudo php -v`(while `php -v` works fine). But then `sudo echo $PATH` is exactly the same as `echo $PATH`. – Alan Apr 29 '14 at 19:39
  • 1
    Given that this seems to be a Unix environment problem, you might find more luck asking the basic question about `sudo php -v` not working somewhere like http://serverfault.com – Matt Gibson Apr 29 '14 at 20:32
  • Why do you need `sudo` to create a webapp? That shoudn't be necessary. – Michiel Apr 30 '14 at 07:16
  • @Michael. I need `sudo` because when I don't use it I get `PHP Error[2]: mkdir(): Permission denied in file /opt/lampp/htdocs/yii-project/framework/console/CConsoleCommand.php at line 463`. Do you think that there is a non-sudo workaround? – Alan May 02 '14 at 15:14

1 Answers1

1

Solution:

1) Sudo PATH and user PATH differ. That's why 'sudo php -v' doesn't work.

User's path:

echo $PATH
/home/alan/home/alan/netbeans-8.0/bin/netbeans/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/lampp/bin

A proper way to echo sudo's path:

sudo /usr/bin/printenv PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

2) I've installed PHP from repositories. I can now call 'sudo php'.

sudo apt-get install php5-cli

Thanks Matt and guys from Ubuntu forums(spjackson & SeijiSensei)!

Alan
  • 1,322
  • 1
  • 21
  • 36