4

I would tring to update my php version to the version 5.5+ latest

When I'm looking via /usr/local/bin/php -v in the console I see the version 5.5+ and with php -v it tell me there is the version 5.4 installed.

How can I remove the older version 5.4 and install latest 5.5+ latest?

3 Answers 3

11

Typically I've used the PHP package from liip.ch

From terminal, run:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5

It will not remove the default installation of PHP 5.4 from your system, but it does not have any impact on using PHP 5.5. They address the issue with php -v in their FAQ.

1
  • 1
    Dont forget to sudo vim ~/.profile and add export PATH=/usr/local/php5/bin:$PATH
    – saadlulu
    Aug 18, 2015 at 20:22
5

Prerequisites

Xcode and it's Command line utilities (install form preferences) will give you a gcc compiler to build the php with libjpeg, libpng etc. if you want to build with these.

OR run this command on terminal to install Command line tools

xcode-select --install

Building and installing php:

  • Download the distribution from www.php.net/downloads.php
  • Untar the archive and point your console into the location
  • Now, having still the original old php installed, run php -i | head in the console. What you want is to configure your new php with these flags to ensure you have proper pcre support and everything works just fine.
  • In the php source directory you untarred, run the ./configure script with the flags you just got
  • Build php by running make and sudo make install afterwards. That will actually replace the original php distributed with OS X.

Example sample run terminal commands:

  • Download latest version from http://php.net and after ruin below commands
tar -zxvf php_scource.tar.gz
cd php_source/
php -i | head
./configure --prefix=/usr --with-snmp # ... same flags as previous build
make
sudo make install

end of the workflow for building php and just check latest version from terminal commands

$ php -v

sample output of php -v

PHP 5.5.10 (cli) (built: Mar 27 2014 16:50:31) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
1
  • thanks for you answer, that help me to build a new version, but instead of overwrite the version shipped with OSx doing as you said, I compile the latest version of PHP within /usr/local/php5 then add to your my path, so the old version untouched. Aug 6, 2014 at 4:23
0

OSX Mavericks runs PHP from /usr/bin/php so in order to run the new version that you want from /usr/local/bin/php, you need to copy this file over to the /usr/bin directory. If you want to save your old version of php, first go to the /usr/bin directory

cd /usr/bin

and rename your old php file

sudo mv php php.old

Then go to the /usr/bin/local directory:

cd /usr/local/bin

and then copy the php file over to /usr/bin using sudo:

sudo cp php /usr/bin

OSX Mavericks has /usr/bin first in its environment path, so the php in /usr/bin is found before it gets to the php in /usr/local/bin. Once you copy your new php file over, when you run

php -v

Which will display something like:

PHP 5.6.23 (cli) (built: Jun 24 2016 21:08:07) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

It will have your new version that was installed at /usr/local/bin/php that you copied over to /usr/bin/php instead of version 5.4. If you're running Apache and want your webserver to also use the new php version, you'll also need to update the httpd.conf file to point at the new php_module, but that's a different question.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.