?>

Updating to PHP5.3 with MacPorts

Previously, I wrote about using two versions of PHP with macports . In it I covered installing PHP4 and PHP5. Since then PHP5.3 has been released as a stable release. However, I needed to maintain my PHP5.2 installation as I have a number of client projects that are on servers using PHP5.2. So to reduce version insanity I wanted to keep 5.2.x around as well.

Backup config files

The first step to updating PHP for me is always to backup my config files. I’ve been stung a few times by updating PHP to new minor versions, which in turn upgrades Apache2 which blows up all my config files. This made me sad the first time it happened. So everytime since then I’ve always made a backup just in case apache2 got updated and my config files got blown up.

Uninstall PHP 5.2 and install PHP 5.3

The fine people at macports have added a php52 package, so the first step I took was deactivating & uninstalling all my php5 packages. Once they were dead and gone I installed PHP 5.3 via the php5 package. Once installed I thought I was all set, but I was wrong. Seems that all the database driver sets have been removed from the core PHP5 package. So make sure you install the database drivers you need. I needed php5-mysql, php5-sqlite, and php5-postgresql.

Install PHP 5.2

First step I did was to deactivate php5 so no activation conflicts showed up. I then installed the php52 with the required variants. After this step I had PHP 5.2, 5.3 and 4.4.9 installed and ready to go. All that was needed was updating my php-switch script, from the last post. So here is the updated copy with support for all 3 PHP’s

xDebug

My love for xDebug has not waned either, so getting xDebug setup needed to be done. Once again I copied the xDebug binaries from ActiveState into their respective directories /opt/local/lib/php5 for PHP5.3 and /opt/local/lib/php52 for PHP5.2, which you will need to make. However, since the php5 and php52 port share the same config file, I used symlinks modified by my php-switch script to point /opt/local/lib/php/extensions/linked at the correct binaries. In my php.ini file I linked the xDebug extension to the symlink address (/opt/local/lib/php/extensions/linked/xdebug.so), so that it is correct for both PHP 5.2 and PHP 5.3.

Switch Script

Last time I posted my php-switch script, and got good feedback about it, so once again I’ll post the updated script.

Show Plain Text
  1. #!/usr/bin/env bash
  2. /opt/local/apache2/bin/apachectl stop
  3.  
  4. case "$1" in
  5. 'php4')
  6. /opt/local/bin/port deactivate php5
  7. /opt/local/bin/port deactivate php52
  8. /opt/local/bin/port activate php4
  9. cp /opt/local/apache2/conf/httpd.php4.conf /opt/local/apache2/conf/httpd.conf
  10. ;;
  11.  
  12. 'php52')
  13. rm /opt/local/lib/php/extensions/linked
  14. /opt/local/bin/port deactivate php4
  15. /opt/local/bin/port deactivate php5
  16. /opt/local/bin/port activate php52
  17. ln -s /opt/local/lib/php52/extensions /opt/local/lib/php/extensions/linked
  18. cp /opt/local/apache2/conf/httpd.php5.conf /opt/local/apache2/conf/httpd.conf
  19. ;;
  20.  
  21. 'php5')
  22. rm /opt/local/lib/php/extensions/linked
  23. /opt/local/bin/port deactivate php4
  24. /opt/local/bin/port deactivate php52
  25. /opt/local/bin/port activate php5
  26. cp /opt/local/apache2/conf/httpd.php5.conf /opt/local/apache2/conf/httpd.conf
  27. ln -s /opt/local/lib/php5/extensions /opt/local/lib/php/extensions/linked
  28. ;;
  29. esac
  30.  
  31. /opt/local/apache2/bin/apachectl start

Unlike last time, this one has to create some links for the extension directories. This is because of the shared php.ini file between PHP5.2 and PHP5.3. Once again I have this file in /opt/local/bin/php-switch and made it world executable. So there you go, multiple PHP versions and an easy way to switch between them.

Update There was an issue with the original script I posted. By deleting /opt/local/lib/php/extensions you lost all your database extensions. I’ve update the switch script and instructions to make this not happen.

Comments

Correction: That should be php5-postgresql not php5-postgresql83.

Otherwise, a great guide, Mark.

Graham Weldon on 9/8/09

Graham: Thanks, updated :)

mark story on 9/8/09

Which debug client do you use for xdebug?
Thanks for this article!

Rafael Vega on 4/28/10

Comments are not open at this time.