Best way to upgrade PHP 5.3 to 5.4

Ryan Schmidt ryandesign at macports.org
Fri Apr 19 15:03:57 PDT 2013


On Apr 19, 2013, at 13:49, Tim Johnson wrote:
> * Ryan Schmidt [130418 20:15]:
>> Perhaps you're using the PHP that comes with OS X. Or perhaps you
>> installed another copy somewhere.
>  I'm pretty sure that it came with OS X. 
> 
>> Are you using PHP in a web server? If so, what web server? OS X's
>> included copy of Apache 2 or something else? Its configuration
>> file will no doubt have an entry for enabling PHP which should
>> help you figure out where it is.
>  Using Apache installed via macportss 

Hmm, ok. It's not intended to mix and match components. You should either use Apple Apache and Apple PHP, or MacPorts Apache and MacPorts PHP.


>>>> If you want php 5.4 for use as an Apache module, you would:
>>> 
>>>> 	sudo port install php54-apache2handler
>>> Understood, and previously would I invoke 
>>> sudo port install php54
>> 
>> Previously, you would use
>> 
>> 	sudo port install php5 +apache2
>> 
>> The php5 port is part of the "old" MacPorts PHP world. Instructions for the "old" way are part of this documentation:
>> 
>> https://trac.macports.org/wiki/howto/MAMP#php
> 
>> A year ago I rewrote PHP in MacPorts. The new MacPorts PHP world
>> is composed of multiple ports with prefixes php53, php54 and php55
>> to let you choose the version(s) you want to use. Our
>> documentation still needs to be updated to explain these new
>> ports.
> 
>> Aside from the Apache 2 module in the php54-apache2handler port,
>> you also have the choice of using php54-cgi or php54-fpm; as I
>> understand it, FPM is the "new hotness" for PHP:
>  I _think_ I want php54-cgi 
> 
>> http://php.net/manual/en/install.fpm.php
>  Yeah, probably no need on my workstation, which does not serve
>  the outside world.

It's your choice. If using the Apache web server, then the easiest option is to install PHP as an Apache module. But you can probably find instructions out there for how to get Apache to talk to PHP as a CGI or using FPM if you prefer those.



>> The php54 port itself contains the command-line version of PHP and some support files, which you will get in any case.
>  php 5.3~ (the 'native' install) is at /usr/bin. 
>  I presume that php5 will be installed via macports to somewhere
>  other than that - like /opt/local ? Thus, giving an easy roll-back
>  option?

Yes, MacPorts installs to /opt/local, specifically so that it does not conflict with your system software.


>  So I need: 
>  sudo port install php5 +php54-apache2handler +php54-cgi
>  ??

No; the "+" syntax is for enabling variants. The above command says "install the php5 port with the variants php54-apache2handler and php54-cgi enabled." The php5 port does not have any such variants, which you can verify as follows:

	$ port variants php5
	php5 has the variants:
	   apache: Add Apache 1 web server module
	     * conflicts with apache2 no_web
	[+]apache2: Add Apache 2.2 web server module
	     * conflicts with apache no_web
	   debug: Enable debug support (useful to analyze a PHP-related core dump)
	   fastcgi: Add FastCGI web server binary
	     * conflicts with no_web
	   ipc: Add semaphore, shared memory and IPC functions
	   no_web: Don't include any web server support
	     * conflicts with apache apache2 fastcgi
	   pear: Add PEAR
	   suhosin: Add Suhosin patch
	   universal: Build for multiple architectures


As I said, the php5 port is "old" MacPorts PHP and I no longer recommend its use. Instead, use the "new" MacPorts PHP ports which have php53, php54 and php55 prefixes. Also, in the new ports, the various server APIs ("SAPIs": apache2, CGI) have been moved from variants to separate ports (and the FPM SAPI, which we did not have in "old" MacPorts PHP, is available as well).

So the correct way to install PHP 5.4 in MacPorts with Apache2 support is:

	sudo port install php54-apache2handler

Or if you want CGI instead (or in addition):

	sudo port install php54-cgi


Also, don't forget the dozens of PHP modules you can install for each version of PHP; these are also separate ports with php53, php54 and php55 prefixes. If you want to see all the ports available in the PHP 5.4 world, for example, you can use:

	port echo name:^php54





More information about the macports-users mailing list