Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing PHP 5.4 and 5.3 side by side on Max OSX via MacPorts

##Given Apache 2 and MySQL are already installed.

#Update MacPorts sudo port selfupdate;sudo port -u upgrade outdated

#Install PHP 5.4.* sudo port install php54 php54-apache2handler ##Activate Apache Module cd /opt/local/apache2/modules sudo /opt/local/apache2/bin/apxs -a -e -n php5 ##Install your needed extensions sudo port install php54-curl php54-ftp php54-iconv php54-mbstring php54-mcrypt php54-mysql php54-openssl php54-soap php54-sqlite php54-xsl php54-zip php54-xdebug php54-mongo #Install PHP 5.3.* sudo port install php53 php53-apache2handler ##Install your needed extensions sudo port install php53-curl php53-ftp php53-iconv php53-mbstring php53-mcrypt php53-mysql php53-openssl php53-soap php53-sqlite php53-xsl php53-zip php53-xdebug php53-mongo #Activate PHP 5.4.* sudo port select php php54 #Fall back to PHP 5.3.* when required sudo port select php php53 The current php_select doesn't change the LoadModule directive in your http.conf so you might have to change the version by hand (and restart your Apache). #Install PEAR cd # curl -o go-pear.phar sudo php go-pear.phar Modify the PEAR install process to your needs; mine were the following:

1. Installation base ($prefix) : /opt/local/lib/php54
4. Binaries directory          : /opt/local/bin

##Check the PEAR installation, cleanup and install your favourite packages

pear info pear && rm go-pear.phar
sudo pear config-set auto_discover 1; sudo pear install

This comment has been minimized.

Copy link

@robsonpeixoto robsonpeixoto commented Jun 8, 2012

If the PHP was compiled with suhosin, you will need to add


on php.ini


This comment has been minimized.

Copy link

@Devric Devric commented Jul 15, 2012

i have a issue with php.ini,

for some reason it is not loaded. Im using php5.3 before (the default mac snow leopard),
than i did the above as suggested.
and did a phpinfo();

it points to 5.4.4 which is correct;

but no matter what i do in /etc/php.ini and restart apache
it does not take effect, anyone know what is wrong with this?

--------------- update --------------
if i use php -i in commandline, everything is fine, it seems like the php.ini is working
I tested if PDO or mongo driver is loaded, it shows fine in the commandline,

BUT if look through browser, it dosent; i browsed localhost/test.php << with << <? phpinfo();
changes in php.ini doesnt show up, and it seems like using the original for php5.3 but the version is point correctly to 5.4.4
i realise the configure ini path is pointing differently

how do i set this path?

i realise that using the web sharing option sharing will trigger the default apache setting, need to start apache2 manually


This comment has been minimized.

Copy link

@robsonpeixoto robsonpeixoto commented Aug 27, 2012

The ports php54-pear and php53-pear add /opt/local/lib/php/pear to include_path.

I think is better configure like that:

  1. Installation base ($prefix) : /opt/local/lib/php/pear

This comment has been minimized.

Copy link

@jrschumacher jrschumacher commented Nov 1, 2012

is there a way to use htaccess files to choose 53 for a project?


This comment has been minimized.

Copy link

@TravelingTechGuy TravelingTechGuy commented Nov 28, 2012

Thanks for taking the time to put this together.
Is there an easy way to find out which php extensions do I have installed currently? I'd like to have the same list for 5.4.
I tried port list | grep php53- but got way too many...


This comment has been minimized.

Copy link

@markhalliwell markhalliwell commented Jan 8, 2013

To get the list of installed ports matching a type of string you should use:
port installed php* (for both php53 and php54)
port installed php53*
port installed php54*


This comment has been minimized.

Copy link

@arm1n arm1n commented Feb 2, 2013

Hi guys, have found your gist yesterday when searching for a possibility to have two php versions with macports. Thanks for the helping instructions. Indeed, the builtin sudo port select php php5x doesn't work as expected, therefore I've written a little shell which changes the httpd.conf file with sed. Hope this helps anybody else:


This comment has been minimized.

Copy link

@ghost ghost commented Mar 1, 2013

I installed this successfully & php -v showing it right.
But from my code, if I do phpinfo(), it's showing me PHP Version 5.3.15.
Any idea how can I fix it?



This comment has been minimized.

Copy link

@someonewhoisme someonewhoisme commented Mar 7, 2013

You can try going into /private/etc/apache2 and changing the httpd.conf file that's there so it has the line "LoadModule php5_module /opt/local/apache2/modules/" somewhere in the list of LoadModule statements.


This comment has been minimized.

Copy link

@brandont brandont commented Jun 29, 2013

Thank you! This worked for me.


This comment has been minimized.

Copy link

@SWW13 SWW13 commented Nov 26, 2013

thx works great, even with php 5.5 just replace php54 with php55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment