10.6. 3 > Terminal > php cli > permission denied

Discussion in 'macOS' started by lucadg, Apr 23, 2010.

  1. lucadg macrumors newbie

    Joined:
    Apr 23, 2010
    #1
    Hi All,
    after hours of searching and trials I give up and ask for help.

    I am trying to install Symfony (a php framework) locally and have installed MAMP.

    Symfony asks me to run this command

    Code:
    php lib/vendor/symfony/data/bin/symfony generate:project PROJECT_NAME
    
    but I get

    Code:
    -bash: /usr/bin/php: Permission denied

    now, in /usr/bin/php there is an alias to the location of php which is under MAMP in bin/php5.3/bin and this may be a reason for the error.

    Even

    Code:
    php -v 
    gives

    Code:
    -bash: /usr/bin/php: Permission denied
    I tried to login as root, but still nothing.

    I litterraly read all forums online about this, but I just can't get it.
    Thanks for help :)
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    Does PHP work inside MAMP normally? If so then the cause is almost certainly that the executable bit isn't set on the PHP binary. That's easy to fix: change directories to /Applications/MAMP/bin/php5.3/bin and issue this command:
    Code:
    chmod +x php
    Then, try again.
     
  3. Hal Itosis macrumors 6502a

    Hal Itosis

    Joined:
    Feb 20, 2010
    #3
    Some things to look at (and/or show us):

    type -a php
    ls -l /usr/bin/php
    ls -laL /usr/bin/php
    [ -e /usr/bin/php ] && echo linked || echo broken
     
  4. lucadg thread starter macrumors newbie

    Joined:
    Apr 23, 2010
    #4
    Hi,

    yes, no problem there.

    Ok, I tried

    Code:
    chmod +x php
    and then

    Code:
    php -v
    but it still gives

    Code:
    -bash: /usr/bin/php: Permission denied
    after that.

    Code:
    ls -l /usr/bin/php
    
    gives
    
    -rw-rw-rw-@ 1 lucadegiglio  staff  47636 21 Apr 20:28 /usr/bin/php
    
    
    ls -laL /usr/bin/php
    gives
    -rw-rw-rw-@ 1 lucadegiglio  staff  47636 21 Apr 20:28 /usr/bin/php
    
    [ -e /usr/bin/php ] && echo linked || echo broken
    gives
    linked
    
    
    How does it look?
    The patient has hope? :)

    Thanks for your help!
     
  5. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #5
    sudo chmod +x /usr/bin/php

    Though I'm curious why there's an ACL associated with php.. Or is that an immutable flag. rusty cli :(
     
  6. Hal Itosis macrumors 6502a

    Hal Itosis

    Joined:
    Feb 20, 2010
    #6
    Not so hot. I'm not seeing that "alias" you mentioned earlier in post #1:
    >> now, in /usr/bin/php there is an alias to the location of php which is
    >> under MAMP in bin/php5.3/bin and this may be a reason for the error.

    /usr/bin/php looks to be an ordinary file... which for some reason you own and the group staff claims membership. Doesn't look right at all... but then again i have Leopard 10.5.8 here:
    Code:
    [COLOR="Blue"]ls -l /usr/bin/php[/COLOR]
    -r-xr-xr-x  1 root  wheel  14795536 Feb  9 03:35 /usr/bin/php
    
    What i expected (after you brought up "alias") was a symlink something like this...
    Code:
    [COLOR="Blue"]ls -l /usr/bin/ruby[/COLOR]
    [COLOR="Red"]l[/COLOR]rwxr-xr-x  1 root  wheel  76 Mar 14  2009 /usr/bin/ruby -> 
    ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
    
    [COLOR="Blue"]ls -laL /usr/bin/ruby[/COLOR]
    -rwxr-xr-x  1 root  wheel  38304 Jan 28 03:13 /usr/bin/ruby
    
    I.e., "/usr/bin/ruby" is a symlink to a buried executable... but your listing revealed no symlink (or alias either).

    Judging by the type, owner, group and perms on your /usr/bin/php ...
    i'd say you probably should run a permissions repair and try it again.

    --

    Interesting point. The ampersand @ is telling us that one or more extended attributes are associated with his php file... but it could also be masking the presence of an ACL (normally indicated with a +).

    Perhaps we should look again with
    ls -lOe@ /usr/bin/php
     
  7. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #7
    THAT'S it, thanks Hal!
     
  8. lucadg thread starter macrumors newbie

    Joined:
    Apr 23, 2010
    #8
    Hi all,
    sorry for delay, I was away!

    Code:
    luca-de-giglios-macbook:~ lucadegiglio$ sudo chmod +x /usr/bin/php
    Password:
    luca-de-giglios-macbook:~ lucadegiglio$ php -v
    -bash: /usr/bin/php: cannot execute binary file
    here it is
    [​IMG]

    ok, just done. It looks an error was found and fixed
    [​IMG]

    and now the result is

    Code:
    luca-de-giglios-macbook:~ lucadegiglio$ ls -l /usr/bin/php
    -rwxr-xr-x@ 1 root  wheel  47636 21 Apr 20:28 /usr/bin/php
    and

    Code:
    luca-de-giglios-macbook:~ lucadegiglio$ ls -lOe@ /usr/bin/php
    -rwxr-xr-x@ 1 root  wheel  - 47636 21 Apr 20:28 /usr/bin/php
    	com.apple.FinderInfo	   32 
    	com.apple.ResourceFork	47281 
    but the php -v gives "cannot execute binary file"

    Code:
    luca-de-giglios-macbook:~ lucadegiglio$ php -v
    -bash: /usr/bin/php: cannot execute binary file
    what do you reckon? Are we getting closer?

    Thanks!!

    Luca
     

    Attached Files:

  9. guyadam macrumors newbie

    Joined:
    Apr 30, 2010
    #9
    Similar problem

    Hey this might be a solution to your problem... I am not sure, but after a lot of searching and stumbling across this thread... it actually solved my problem.

    Which was, that I kept getting permission denied while entering php -v and also pear -v and most php commands that I was trying to use within the terminal.

    The fix on my part was from wridwzrd89, thanks! I needed to change permissions via chmod and that fixed my dilemma.

    I have the same set up as you in regards to MAMP but what I have done is added a $PATH in my .bash_profile to

    Code:
    PATH=/Applications/MAMP/bin/php5.3/bin:\
    /Applications/MAMP/Library/bin:$PATH
    export PATH
    I think wridwzrd89 post is pretty close to the mark with what I have done. Just to let you know I am not trying to install Symfony framework.

    Hope this might help.
     
  10. lucadg thread starter macrumors newbie

    Joined:
    Apr 23, 2010
    #10
    Hi guyadam

    I did not have one, so I created it and added the code you suggest.
    Still does not work.

    Thanks anyway.

    I am really stuck now :)
     
  11. Hal Itosis macrumors 6502a

    Hal Itosis

    Joined:
    Feb 20, 2010
    #11
    Now that i'm finally running Snow Leopard (new MBP arrived today), here's what i see for php:

    ls -lOe@ /usr/bin/php
    -rwxr-xr-x 1 root wheel - 29034848 Feb 11 19:27 /usr/bin/php

    php -v
    PHP 5.3.1 (cli) (built: Feb 11 2010 16:26:40)
    Copyright (c) 1997-2009 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

    codesign -vvv /usr/bin/php
    /usr/bin/php: valid on disk
    /usr/bin/php: satisfies its Designated Requirement

    md5 /usr/bin/php
    MD5 (/usr/bin/php) = 11d44914713606a5b99f9099efd7ac56
    All i can say is you have installed something which has modified that file significantly. (note that my php file is 600 times larger than yours). I'm guessing that Finder alias you have there should be a symlink instead...

    ::shrug::

    Try asking in the MAMP forums maybe.
     
  12. lucadg thread starter macrumors newbie

    Joined:
    Apr 23, 2010
    #12
    I have opened the window and was trying to throw the Mac away, but my fingers accidentaly typed php -v in the terminal and I got

    Code:
    PHP 5.3.2 (cli) (built: Mar  5 2010 16:45:34) 
    Copyright (c) 1997-2010 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
        with XCache v1.3.0, Copyright (c) 2005-2009, by mOo
    ....so I guess that the previous actions took effect after a reboot or something...and you guys saved my Mac.
    I owe you one!
     
  13. Hal Itosis macrumors 6502a

    Hal Itosis

    Joined:
    Feb 20, 2010
    #13
    If anything, it was the PATH tweak posted by guyadam.
     
  14. gorn macrumors member

    Joined:
    Jun 17, 2009
    #14
    Just FYI the real problem was that you created an alias for PHP rather than a symbolic link. Aliases are Mac-only and don't play nice on the cli. symlinks do.

    To fix your /usr/bin/php you can do:
    ln -sf /Applications/MAMP/bin/php5.3/bin/php /usr/bin/php

    maybe with a sudo in front of it.
     
  15. lucadg thread starter macrumors newbie

    Joined:
    Apr 23, 2010
    #15
    works now...do you suggest to do this anyway?
     

Share This Page