简体   繁体   中英

Wrong php version for /usr/bin/php

I am using OSX El Capitan and I see that /usr/bin/php is using wrong php version.

which php
/usr/bin/php

php -v
PHP 5.5.34 (cli) (built: Apr 22 2016 19:16:58) 

I have installed latest MAMP and I tried to create a symlink to the correct version

sudo ln -sf /Applications/MAMP/bin/php/php7.0.9/bin/php /usr/bin/php
Password:
ln: /usr/bin/php: Operation not permitted

Can anyone suggest how can I fix this?

I solved it using different approach then disabling SIP

sudo nano ~/.bash_profile

I have added

alias php="/usr/local/bin/php"

Then I added a symlink

sudo ln -sf /Applications/MAMP/bin/php/php7.0.9/bin/php /usr/bin/php

And then I checked php version

php --version

And it showed 7.0.9 as expected

Your real problem is Mac SIP (System Integrity Protection). When SIP is enabled you can't write anything to /usr (with the exception of /usr/local). Disable it and make the symlink. Make sure to re enable SIP after symlink creation.

To disable SIP

1)Reboot the Mac and hold down Command + R keys simultaneously after you hear the startup chime, this will boot OS X into Recovery Mode.

2)When the “OS X Utilities” screen appears, pull down the 'Utilities' menu at the top of the screen instead, and choose “Terminal”

3)Type the following command into the terminal then hit return:

csrutil disable; reboot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM