How to update PHP on Mac OS X?

I feel this is a terribly dumb question, but, oddly enough, this problem is poorly documented.

I want to update PHP, but there are a few problems:

  • There is no built-in package manager. MacPorts does not recognize php as an installed package because it did not install PHP itself.
  • Running locate php indicates that there are probably a lot of dependencies.
  • I do not know how php was installed, since it was included in the OS, so I do not know whether to install from source code or download binary files. I also do not know how to correctly remove the previous version without breaking the dependencies.

I am running on a Leopard. I feel like Apple doesn't want you to update. Will Snow Leopard buy and updates solve this problem (and future ones like it)?

+84
php macports macos
Mar 26 '10 at 19:22
source share
11 answers

You might want to check out the Marc Liyanage PHP package. It comes with a Mac OS X installer that you can double-click. He keeps him updated on the latest developments.

http://php-osx.liip.ch/

Also, while upgrading to Snow Leopard will not help you upgrade PHP in the future, it will probably give you a newer version of PHP. I am running OS X 10.6.2 and have PHP 5.3.0.

+75
Mar 26 '10 at 19:52
source share

I use this: https://github.com/Homebrew/homebrew-php

Team:

 $ xcode-select --install $ brew tap homebrew/dupes $ brew tap homebrew/versions $ brew tap homebrew/homebrew-php $ brew options php56 $ brew install php56 

Then enter the configuration in .bash_profile or .bashrc

 # Homebrew PHP CLI export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH" 
+44
Mar 11 '16 at 2:28
source share

There is no built-in package manager. MacPorts does not recognize php as an installed package because it did not install PHP itself.

You can still install it using MacPorts. sudo port install php52 (or whatever version you want) will install PHP.

It will not overwrite the version provided by Apple. It will install it under /opt/local . You can add /opt/local to the top of your $PATH and use the MacPorts version in your Apache configuration.

+8
Mar 26 '10 at 19:24
source share

Option number 1

As recommended here , this site provides a convenient, give one insert.

This does not overwrite the base version of PHP on your system, but installs it purely in / usr / local / php 5.

Option number 2

My preferred method is to simply install via Homebrew .

+5
Apr 22 '13 at 16:41
source share

Before continuing, I have the latest version (v5.0.15) of OS X Server (yes, terrible, I know ... however, the web server seems to be running A-OK). I searched high and low for several days trying to upgrade (or at least get Apache) a new version of PHP. My mcrypt did not work along with other extensions, and I installed and re-installed PHP countless times from http://php-osx.liip.ch/ and other tutorials until I finally noticed a bit of information written in a comment in one Of the many different .conf files, OS X Server supports OS X Server loading its own custom .conf file before it loads Apache httpd.conf (located in /etc/apache2/httpd.conf ). Server file is located:

 /Library/Server/Web/Config/apache2/httpd_server_app.conf 

When you open this file, you should comment on this line as follows:

 #LoadModule php5_module libexec/apache2/libphp5.so 

Then add the correct path (which should already be installed if you installed the link http://php-osx.liip.ch/ ):

 LoadModule php5_module /usr/local/php5/libphp5.so 

After this modification, my PHP finally downloaded the correct PHP installation. At the same time, if everything went wrong, perhaps this is due to the fact that OS X is used to work with your own PHP installation during OS X installation. To return, simply undo the change above.

In any case, we hope that it will be useful for everyone who spends countless hours on it.

+3
Dec 01
source share

I think one easy way to do this is:

1 - Check where your current PHP is located:

 $ which php $ /usr/local/bin/php 

You see? Usually our commands that we run are a link in / usr / local / bin, so ...

2 - Unlink this current PHP link

 unlink /usr/local/bin/php 

If you prefer, before disabling it, check the path and then delete the php files (do ls -al /usr/local/bin | grep php and then rm -rf to the desired path)

3 - Install PHP 7.1

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

4 - Create a new link (using installed php 7.1 bin)

 ln /usr/local/php5-7.1.9-20170914-100859/bin/php /usr/local/bin/php 

As I said, this is an easy way, I think.

+3
Sep 21 '17 at 18:01
source share

Upgrading to Snow Leopard will not solve your primary problem of keeping PHP up to date. Apple does not always support third-party software that it updates with OS updates. And relying on Apple to get the bug fix / security update you need, there is a problem.

In addition, I would recommend installing through MacPorts (and making the configuration necessary to use it instead of Apple PHP) rather than trying to update the PHP provided by Apple. Everything you do with /usr/bin may be overwritten by some future Apple update.

+2
Mar 26 '10 at 19:35
source share

Keeping keystrokes, this worked on MacOS Sierra:

 $ brew install homebrew/php/php71 $ /usr/local/opt/php71/bin/php -v PHP 7.1.4 (cli) (built: Apr 14 2017 15:02:16) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies 
+2
Apr 18 '17 at 13:47 on
source share

Check the current php version in the terminal with the following command:

 $ php -v 

You see the current php version in the terminal and run the following command in the terminal if you want to update the php version using php concat with the version you like,

 $ brew install homebrew/php/php71 

Please restart the terminal if you have finished updating the PHP version and run the command.

 $ php -v 

Now you see the current php version in the terminal .... thank

+2
Jun 07 '17 at 9:36 on
source share

Best way to update compile it from source

see this tutorial that may be useful to you

http://www.computersnyou.com/2012/09/how-to-upgrade-php-in-mac-osx-compiling.html

-one
Sep 08
source share

to upgrade php7 to the latest stable version of brew upgrade php7 or for php5.X to the latest stable version

 brew upgrade php56 

use brew list to check installed version

-2
Oct 13 '16 at 8:28
source share



All Articles