Page 1 of 1

This is one way to upgrade your PHP versions

Posted: Fri Apr 14, 2006 11:42 am
by Whatevakid
This Does Require A Moderate knowledge of PHP.



Find Packages to upgrade

First you need to figure out which additional packages you need to upgrade. You can do this using the equery tool, part of the app-portage/gentoolkit package:

Code Listing 3.1: list installed packages in dev-php

$ equery list 'dev-php/'
[ Searching for all packages in 'dev-php' among: ]
* installed packages
[I--] [ ] dev-php/php-4.4.0 (0)
[I--] [ ] dev-php/mod_php-4.4.0 (1)
[I--] [ ] dev-php/smarty-2.6.10 (0)
[I--] [ ] dev-php/PEAR-PEAR-1.3.5-r1 (0)
[I--] [ ] dev-php/PEAR-Mail-1.1.6 (0)
[I--] [ ] dev-php/PEAR-MDB-1.3.0 (0)
[I--] [ ] dev-php/PECL-apc-3.0.6 (0)
[I--] [ ] dev-php/PECL-imagick-0.9.11 (0)
[I--] [ ] dev-php/xdebug-2.0.0_beta3 (0)

Important: The packages you have installed may be vastly different, make sure you run this command for yourself. You should store your list generated above, to make sure you will upgrade all packages.

Note: Many webapps aren't affected in any way as most use the webapp eclbobba which takes care of installing them correctly. You may want to check to see if there is a new revision.

PHP extensions, such as

* PECL-apc
* PECL-imagick
* xdebug

have been splitted into 2 seperate portage categories dev-php4 and dev-php5, to make it possible to use them independently for both PHP versions. Additionally most of these packages have been renamed:

Examples for new directories and renaming:
PHP Extension old new PHP4 new PHP5
APC dev-php/PECL-apc dev-php4/pecl-apc dev-php5/pecl-apc
Imagick dev-php/PECL-imagick dev-php4/pecl-imagick dev-php5/pecl-imagick
Xdebug dev-php/xdebug dev-php4/xdebug dev-php5/xdebug

Note: Before emerging these extensions again, you have to find out in /usr/portage, how the packages have been renamed.

Remove old Packages

We have made many changes to how PHP works within Gentoo. You have to completely remove your old PHP packages, before installing the new packages:

Code Listing 3.2: remove old packages (example)

(unmerge PHP packages)
emerge --unmerge php mod_php

(unmerge PHP extensions)
emerge --unmerge PECL-apc PECL-imagick xdebug

(unmerge PHP libraries/applications)
emerge --unmerge PEAR-PEAR PEAR-Mail PEAR-MDB smarty

Set the USE flags

As we have added some new USE flags, you may want to review them and add appropriate lines to /etc/portage/package.use (has to be created if it doesn't exists).

Note: /etc/portage/package.use will set the USE flags for your PHP installation and remember them without mbobba editing through make.conf.

Please set the USE flags accordingly to what you want your PHP installation to support (it is recommended to at least set the cli USE flag):

Code Listing 3.3: USE flags for dev-lang/php (example)

dev-lang/php -* cli apache2 ctype expat fastbuild ftp gd hash iconv memlimit mysql nls pcre pic pdo reflection session simplexml sockets spl ssl tokenizer truetype xml xsl zlib

Note: -* will disable all USE flags (this will disable even basic PHP features like Session-, PCRE-, gd- and MySQL-support!), so you have to specify every USE flag for any extension/feature you would like to use. See Managing Extensions for details. You have to set USE flags for upstream's defaults such as pcre if you want to use preg_* Functions or session if you want to use Session Handling Functions.

If you want to install PHP4 and PHP5 in parallel, you can put in different USE flags for each version:

Code Listing 3.4: different USE flags for PHP4 and PHP5 (example)

=dev-lang/php-4* -* cli cgi apache2 ctype expat fastbuild force-cgi-redirect ftp gd iconv ipv6 memlimit mysql nls pcre pic posix session sockets ssl tokenizer truetype xml xsl zlib
=dev-lang/php-5* -* cli cgi apache2 ctype fastbuild force-cgi-redirect ftp gd hash iconv ipv6 memlimit mysql nls pcre pic posix pdo reflection session simplexml soap sockets spl sqlite ssl tokenizer truetype xml xmlreader xmlwriter xsl zlib

Note: For a list of recommended USE flags look at Recommend USE flags. For a list of USE flags available for PHP have a look at the USE flags table from overlay wiki.

Emerge PHP

Now you have the choice to install PHP4 only, PHP5 only or both in parallel. To install PHP4 only you have to emerge =dev-lang/php-4*, to install PHP5 (latest) you can use dev-lang/php, and to install both in parallel you have to emerge =dev-lang/php-4* and =dev-lang/php-5*.

Check USE flag settings:

Code Listing 3.5: check USE flags (example)

(check PHP4 package)
emerge --pretend --verbose '=dev-lang/php-4*'

(check PHP5 package)
emerge --pretend --verbose '=dev-lang/php-5*'

(check PHP extensions for PHP4)
emerge --pretend --verbose dev-php4/pecl-apc dev-php4/pecl-imagick dev-php4/xdebug

(check PHP extensions for PHP5)
emerge --pretend --verbose dev-php5/pecl-apc dev-php5/pecl-imagick

(check PHP libraries/applications)
emerge --pretend --verbose PEAR-PEAR PEAR-Mail PEAR-MDB smarty

Emerge PHP if everything is fine:

Code Listing 3.6: emerge new packages (example)

(emerge PHP4 package)
emerge '=dev-lang/php-4*'

(emerge PHP5 package)
emerge '=dev-lang/php-5*'

(emerge PHP extensions for PHP4)
emerge dev-php4/pecl-apc dev-php4/pecl-imagick dev-php4/xdebug

(emerge PHP extensions for PHP5)
emerge dev-php5/pecl-apc dev-php5/pecl-imagick

(emerge PHP libraries/applications)
emerge PEAR-PEAR PEAR-Mail PEAR-MDB smarty

PHP4 and PHP5 parallel: select which cli/cgi binary to use

After emerging you will have binaries for cli and/or cgi in /usr/lib/php4/bin and/or /usr/lib/php5/bin. If you have installed both, PHP4 and PHP5, portage cannot decide for you which one should be used by default and always symlinks the last PHP version you installed in /usr/bin. So if you installed PHP5 as last, you'll see /usr/bin/php symlinked to /usr/lib/php5/bin/php. So one cli and/or cgi binary as well as php-devel (responsable for building PHP extensions using phpize and php-config) has to be symlinked (in /usr/bin), which could easily be done using php-select, which is part of app-admin/php-toolkit.

Note: The dev-lang/php packages depend on app-admin/php-toolkit so php-select should be available automatically after emerging the new style php packages.

bobbauming you have emerged =dev-lang/php-4* as well as =dev-lang/php-5*, enter the following php-select commands to show the currently selected PHP versions:

Code Listing 3.7: show currently selected PHP versions

(for cli)
php-select php

(for cgi)
php-select php-cgi

(for phpize, php-config)
php-select php-devel

You should see something like that:

Code Listing 3.8: example output of php-select

# php-select php
/usr/bin/php is set to /usr/lib/php5/bin/php

Which means that the default path to the PHP cli binary /usr/bin/php is symlinked to the PHP5 binary /usr/lib/php5/bin/php. So PHP scripts using /usr/bin/php will be executed by PHP5.

Use php-select to change default PHP versions

If you are not happy with the default version settings you found out in the last chapter, you can use php-select again to select the desired version:

Code Listing 3.9: select desired versions

(for cli)
php-select php php4

(for cgi)
php-select php-cgi php5

(for phpize, php-config)
php-select php-devel php5

Note: Please type php-select -h to get more details on what php-select can do.

Check linking:

Code Listing 3.10: check symlinks

# stat /usr/bin/php /usr/bin/php-cgi /usr/bin/phpize /usr/bin/php-config | grep File
File: `/usr/bin/php' -> `/usr/lib/php4/bin/php'
File: `/usr/bin/php-cgi' -> `/usr/lib/php5/bin/php-cgi'
File: `/usr/bin/phpize' -> `/usr/lib/php5/bin/phpize'
File: `/usr/bin/php-config' -> `/usr/lib/php5/bin/php-config'

Note: Please note that php-select only changes the default versions. If you have installed both, PHP4 and PHP5 cgi/cli you can allways use the direct paths like /usr/lib/php4/bin/php and /usr/lib/php5/bin/php to run a PHP script with a specific version. You can use PHP4 and PHP5 cgi in the same Apache instance, but you cannot use two different PHP Apache modules in one Apache instance, see PHP4 and PHP5 Configuration Guide for details.

Thanks,
Kris

Posted: Fri Apr 14, 2006 11:43 am
by Whatevakid
Hope that heaps someone :P

Posted: Tue Apr 18, 2006 12:40 am
by Whatevakid
Did it help anyone? :lol: