Tuesday, July 6, 2010

Upgrading to PHP 5.3 ports on FreeBSD

Environment:
FreeBSD

php5-5.2.12         PHP Scripting Language
php5-curl-5.2.12    The curl shared extension for php
php5-dom-5.2.12     The dom shared extension for php
php5-gd-5.2.12      The gd shared extension for php
php5-iconv-5.2.12   The iconv shared extension for php
php5-mbstring-5.2.12 The mbstring shared extension for php
php5-mysql-5.2.12   The mysql shared extension for php
php5-openssl-5.2.12 The openssl shared extension for php
php5-pcre-5.2.12    The pcre shared extension for php
php5-pdo-5.2.12     The pdo shared extension for php
php5-pdo_mysql-5.2.12 The pdo_mysql shared extension for php
php5-session-5.2.12 The session shared extension for php
php5-simplexml-5.2.12 The simplexml shared extension for php
php5-spl-5.2.12     The spl shared extension for php
php5-xml-5.2.12     The xml shared extension for php
php5-xsl-5.2.12     The xsl shared extension for php
php5-zip-5.2.12     The zip shared extension for php
php5-zlib-5.2.12    The zlib shared extension for php
pecl-stem-1.5.0     A PECL extension which provides word stemming

Task:
Upgrade all ports to php5-5.3.2

  1. Some of the functions are deprecated in PHP 5.3. I had to replace all occurrences of split() with explode() or preg_split() and mysql_escape_string() with mysql_real_escape_string(). Note that mysql_real_escape_string() requires second parameter - DB connection.
  2. Attempt to upgrade ports with `portupgrade php5*` did not work. Some of the extensions do not exist anymore in PHP 5.3, and `pkgdb` was quite confused. I had to delete all php5 ports and then install them again.
  3. PHP 5.3 installed extensions into a new folder /usr/local/lib/php/20090626. My php.ini had reference to the old one, /usr/local/lib/php/20060613. Had to change that manually.
  4. pecl-stem-1.5.0 was not marked for upgrade (pkg_version). However, I had to rebuild it, because it was incompatible with the new PHP libraries.
  5. `php -i` complained about undefined timezone. I had to add date.timezone="America/New_York" to php.ini.
  6. I checked which extensions are now "included with PHP by default" (in docs on http://php.net and in /usr/ports/lang/php5-extensions.Makefile), and installed some of them, in addition to what I had before. There was also a nice "fileinfo" extension that I thought could be useful. Here is the list of extensions after upgrade:
php5-5.3.2_1        PHP Scripting Language
php5-ctype-5.3.2_1  The ctype shared extension for php
php5-curl-5.3.2_1   The curl shared extension for php
php5-dom-5.3.2_1    The dom shared extension for php
php5-filter-5.3.2_1 The filter shared extension for php
php5-gd-5.3.2_1     The gd shared extension for php
php5-hash-5.3.2_1   The hash shared extension for php
php5-iconv-5.3.2_1  The iconv shared extension for php
php5-json-5.3.2_1   The json shared extension for php
php5-mbstring-5.3.2_1 The mbstring shared extension for php
php5-mysql-5.3.2_1  The mysql shared extension for php
php5-openssl-5.3.2_1 The openssl shared extension for php
php5-pdo-5.3.2_1    The pdo shared extension for php
php5-pdo_mysql-5.3.2_1 The pdo_mysql shared extension for php
php5-session-5.3.2_1 The session shared extension for php
php5-simplexml-5.3.2_1 The simplexml shared extension for php
php5-xml-5.3.2_1    The xml shared extension for php
php5-xmlreader-5.3.2_1 The xmlreader shared extension for php
php5-xmlrpc-5.3.2_1 The xmlrpc shared extension for php
php5-xmlwriter-5.3.2_1 The xmlwriter shared extension for php
php5-xsl-5.3.2_1    The xsl shared extension for php
php5-zip-5.3.2_1    The zip shared extension for php
php5-zlib-5.3.2_1   The zlib shared extension for php
pecl-fileinfo-1.0.4 A PECL extension to retrieve info about files
pecl-stem-1.5.0     A PECL extension which provides word stemming