Macports switches PHP CLI version
I'm trying to switch my Terminal PHP version to 5.4 because I'm having issues with Drush while updating my Drupal core. https://drupal.stackexchange.com/questions/112090/drush-command-errors
The reason for these problems is my PHP version for terminals is different from my localhost.
php -v
in terminal returns PHP 5.5.13 (cli)
but my localhost is working PHP Version 5.4.29
.
I started looking for how to switch my CLI version to 5.4 and found this:
sudo rm /usr/bin/php // remove /usr/bin/php first
sudo ln -s /opt/local/bin/php54 /usr/bin/php // pointing to php54
php -v // get version
PHP 5.4.9 (cli) (built: Nov 26 2012 12:40:37)
Copyright (c) 1997-2012 The PHP Group
However after doing this and restarting Apache and Terminal I still get
PHP 5.5.13 (cli)
after php -v
.
To make sure I was working in the correct folder, I checked to see if the file was php
deleted after startup sudo rm /usr/bin/php
and it was.
So, as a test, I did this: /opt/local/bin/php54 -v
and got PHP 5.4.29 (cli)
. This makes me think that my symbolic link is not working, or I did something wrong.
Side notes:
After running, sudo rm /usr/bin/php
I expected to php -v
give an error in the terminal, however it still gives me PHP 5.5.13 (cli)
.
I also get the same results on startup whereis php
and which php
even after the symlink.
whereis php
returns /usr/bin/php
and which php
returns/opt/local/bin/php
Local address:
#LoadModule php5_module modules/mod_php55.so
LoadModule php5_module modules/mod_php54.so
#LoadModule php5_module modules/mod_php53.so
#LoadModule php5_module modules/libphp5.so
#Include conf/extra/mod_php55.conf
Include conf/extra/mod_php54.conf
#Include conf/extra/mod_php53.conf
#Include conf/extra/mod_php.conf
Bash Profile:
# MacPorts Installer addition on 2012-10-23_at_13:41:14: adding an appropriate PATH $
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# also include mysql binaries
export PATH=$PATH:/opt/local/lib/mysql5/bin
Any help is greatly appreciated.
source to share
Do not modify files in /usr/bin
. This is apple sod and there are always other options to avoid changing there, especially since the next Apple update will happily bring those changes back again, and scripts can rely on /usr/bin/php
like the version of Apple that comes with the OS. Place the original binary where it belongs.
Also, as you noticed which php
(or type php
, which is often more accurate because it includes things like shell aliases), there is a return /opt/local/bin/php
that tells you which php
binary (or symbolic link) is being executed when you type php
in the shell. Since then /opt/local/bin/php
, what do you need to change.
MacPorts has a mechanism that allows you to customize these preferred versions. You have to use it on top of symlinks to places manually, because in addition to the standard PHP binaries, it will also link to related things like php-config
, phpize
and their respective manpages. This mechanism is called port select
.
To see the PHP versions available to choose from, run port select --list php
. To select your preferred version, run sudo port select --set php $versionIdentifier
. For your use, PHP 5.4 probably will sudo port select --set php php54
.
Remember to run hash -r
after this command to clear any caches your shell may have in the location of the binary php
.
source to share