home

upgrading PHP 4 to 5 on gentoo

This page has gotten a lot of hits, hopefully it’s helped some people. I also have some Updates at the bottom of this page from e-mails I’ve received.

Here’s what I did to upgrade our dev ( and a staging test server) from PHP 4 to PHP 5 (and update to the new gentoo Apache Herd Refresh builds).

First, you should probably find out (the easy way) what functions you may be using that are PHP 4 specific. (I did this by migrating the box over first and seeing what broke).

We were using some of the DOM XML extensions (xml libs), that are now not bundled with PHP anymore ( > 5.0.0). It was moved to the PECL repository, and even there is a warning and suggestion that upgrading to PHP 5 — you should use the newer DOM extension (straight DOM, not DOM XML). Just keep this in mind if you’re planning on upgrading. In this case, we’ll just be going for 5.

OK, back to the upgrade. First let’s emerge –sync to get the latest and greatest:

# emerge --sync

If you must emerge portage, do that too:

# emerge --ask --verbose portage

Now let’s just see what packages we’ll need to upgrade when we update apache. You can do this using the equery tool, part of the app-portage/gentoolkit package.

# equery depends net-www/apache

For me on my dev box, that’s just:

# equery depends net-www/apache
[ Searching for packages depending on net-www/apache... ]
dev-php/mod_php-4.4.0
dev-util/subversion-1.2.3

mod_php is now replaced with a php build with the apache2 ( or apache[1] ) option to compile in support, so that’s no worries. And subversion — I’m just using the client, not the webDAV enabled server, so that’s fine.

Now you can opt to go all out, which is not necessary IMHO:

# emerge --pretend --verbose --update --newuse --deep apache subversion 

or get out easy:

# emerge --pretend --verbose apache 

I wouldn’t do deep since I’m going to be replacing at least the PHP build soon anyways, and know there’s some other packages that will get hit then.

Let’s just do apache:

# emerge --ask --verbose apache 

Now, apache will merge with the default options. And since we didn’t specify an “MPM style,” it defaults to mpm-prefork.

Now, update your etc files:

# etc-update

You’ll see some big changes in all these files — make a note of any changes you’ve added, and go ahead and accept the newer updated files (press 1 to choose /etc/conf.d/apache2 , then q when you’re done looking at the diff, then press 1 to replace the original with the update). Go ahead and replace all your config files.

PHP

In the new gentoo PHP layout, all PHP ebuilds dev-php/php, dev-php/php-cgi and dev-php/mod_php have been merged to one ebuild: dev-lang/php.

Now to install PHP 5, it’s still marked as testing (hence the ~x86 flag).

Here’s a great page on how it’s done:

http://svn.gnqs.org/projects/gentoo-php-overlay/file/docs/php-upgrading.html?format=raw

first remove ‘em:

# emerge --unmerge php mod_php smarty

Open up (or create) /etc/portage/package.keywords BUT FIRST, go read:

The Gentoo Handbook - Working with Portage - Section 1 at least.

After reading, you can now add:

dev-lang/php
app-admin/eselect
app-admin/eselect-php
dev-php5/pecl-apc
dev-php/PEAR-PEAR
dev-php/PEAR-Mail
dev-php/PEAR-MDB
... and any other PEAR packages you must ...
dev-php/smarty

Now open (or create) /etc/portage/package.use and add:

=dev-lang/php-5* cli apache2 dba bcmath ctype curl gd jpeg
 mysql pear pcre pdo-external postgres png session
simplexml soap truetype xml xml2 xsl zlib

(those are all on one line, BTW)

Or whatever options you want. There are a lot of ‘em. These are my fav.

Now unfortunately, one of the PEAR packages is still masked as unstable, so running:

# ACCEPT_KEYWORDS="~x86" emerge --ask --verbose dev-lang/php

works, but we’re installing masked dependecy updates. If you are cool with doing that, by all means go for it. Otherwise, keep adding items to your package.keywords until it works. Let’s move on….

So let her rip (answer Yes, or run this instead):

# ACCEPT_KEYWORDS="~x86" emerge dev-lang/php

Now we’ll need to run etc-update

# etc-update

And accept the new pear.conf

I also at this point re-emerge smarty and add /usr/lib/php/Smarty to my include_path in my /etc/php/apache2-php5/php.ini file. And I add some pear classes I was using:

# pear install DB
# pear install Mail
# pear install Mail_MIME

Now, open up /etc/conf.d/apache2

and add to the line:

APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5"

For me, I have to yank out all my Document config lines from where I shoved them in /etc/apache2/conf/commonapache2.conf, and put them into the newer config location: /etc/apache2/vhosts.d/00_default_vhost.conf

Restarting apache reveals:

# /etc/init.d/apache2 restart
 * Caching service dependencies ...   [ ok ]
 * Found old apache2.conf in /etc/apache2/conf.
 Configuration locations have moved, please check
 /etc/apache2/httpd.conf to make sure
 it is correct, and remove /etc/apache2/conf/apache2.conf.
 Please see http://www.gentoo.org/doc/en/apache-upgrading.xml
 for more information.

So a quick:

# mv /etc/apache2/conf/apache2.conf ~/old_apache2.conf
# /etc/init.d/apache2 restart

has me up and running.


Updates

Someone asked me about doing a fresh PHP5 install and then:

# emerge -pvuD world

without any blocking or masked packages.

Refer to: The Gentoo Handbook - Working with Portage - Section 1.

Look at the section on user-specific files, specifically using /etc/portage/package.keywords

I had to continually try to emerge -pvuD and keep adding PEAR packages until it let me continue. Going through this process about 4 or 5 times, it now lets me update world. My /etc/portage/package.keywords file looks like the following:

dev-lang/php
app-admin/eselect
app-admin/eselect-php
dev-php/PEAR-PEAR
dev-php/PEAR-Archive_Tar
dev-php/PEAR-Console_Getopt
dev-php/PEAR-XML_RPC
dev-php5/pecl-pdo
dev-php5/pecl-pdo-mysql
dev-php5/pecl-pdo-pgsql

I personally don’t like doing an update world because I don’t know what’s going on — also I make modifications to my kernel and build from source, and when you’ve got hibernation (suspend2disk) working on a laptop, and sound, and everything — it’s kind of like: “if it’s not broke, don’t fix it”

But I do like seeing what support I’m missing. I’m on the GLSA (Gentoo Linux Security Announcements) list, for packages that yes, need updating because of security, but if I’m not using a specific feature, no need to install it. That’s what I say….

;-)