How to Create .deb Packages for PHP 5.3 and PHP 6.0

Okay, so I recently got rid of Vista entirely, replacing it with the Hardy Heron. I’ve been playing around with PHP 6 a bit on my Windows computer at work. I so cannot wait for namespaces, late static binding, and true UTF-8 support. So I figured I’d install it on my Heron as well… Hmmm… Where is it?

So PHP 6 deb packages were nowhere to be found,  and I mean nowhere! Dissappointed I thought I’d just get some 5.3 packages instead… what the?!?!? No 5.3 packages either? Nowhere? I couldn’t fathom this. Why not? I wondered. And then I started wondering how to make them myself.

Long story short, these are my instructions on how to build the source code for PHP 5.3-alpha3 and 6.0.0-dev and turn the compiled code into Debian .deb packages to be installed on Ubuntu, Kubuntu and probably other Debian-based systems. If you’re lazy and on a 64-bit machine, there’s a couple of download links at the end of the article. But please read along anyway, so that you know what you’re getting yourself into ;)

Disclaimer: I’m not a certified package maintainer. I’m just a user. I take no responsibility for the packages created here. If they screw up your installation, your problem. Also, the package(s) that you’ll end up with by following this howto lack the “fragmentation” of the original Ubuntu maintained packages. Everything that the resulting compilation of PHP is able to do will be provided and installed by just one package. You won’t get, for instance, a php6-mysql or a php5-pear package by following my instructions, you get just one “all-in-one” package for PHP 5.3 and/or PHP 6, that will provide an Apache module, a CLI binary, various database modules, etc. etc. etc.

So, what does this mean? Well, it means that you might run into unforeseen problems later when installing other packages that depend on a specific sub-feature of PHP. E.g. if you want to install the phpmyadmin package and it depends on php5-mysql, apt-get will want to install that package to satisfy the dependency, even though you already have the mysql extension installed via the “all-in-one” package. So, you’d have to force installation of phpmyadmin, ignoring dependencies, or you might end up screwing up your PHP installation.

I should also note that neither the 5.3 nor the 6.0 package was able to compile with recode support, so you won’t be able to use recode_string() or recode_file() in your code. I also couldn’t get phar to compile, but I noticed that it isn’t available in the Ubuntu packages either, so maybe there’s a good explanation?

The prerequisites for these steps are a lot of developer libraries for PHP related stuff, and of course the GNU C compiler and (auto)make. Before proceeding, I would highly recommend uninstalling all PHP-related packages from your system. Write down the ones that are removed, in case you choose to reinstall later.

When you’re ready, execute the following command to retrieve and install the required prerequisites. There may be more dependencies needed than what I list here. If so, configure and/or make will barf – in that case please use the tip I give later and try to figure it out yourself (and drop a comment) :) Either way, first thing you need to do is open up a console and execute this command to get the dependencies:

If you want to build PHP 6, you’ll also need to get this:

Okay, so next up you need to actually get the source code for your PHP version of choice. Snapshots are built several times a day, so going to the PHP Source Snapshots and manually fetching the latest version would be the best option. In this example I’m using the October 19 2008 08:30 UTC build, which can be fetched from the commandline like so (from now on, if you get your own version, please replace the date I’m using in my code examples with the one of your download): for PHP 5.3:

Or, for PHP 6:

So far, so good. Next step is to configure the packages. At this point, if you’re missing a dependency, configure will fail with some message about a problem with some named feature. If, for instance, it reports some problem with the feature foo, open up your package manager and search for foo; if you find some package about foo with a name ending in -dev, chances are this is the package you need to be able to continue.

In case you’re wondering, the configure settings I use here are based on the ones used to build the original 5.2 packages created by the Ubuntu maintainers. With PHP installed, you can issue a php-config in a terminal to see the configure options used for the currently installed version. That’s what I did ;) This will hopefully ensure maximum compatibility with the rest of the system.

Anyway, fire off this command to configure the PHP 5.3 source code:

Or, for PHP 6.0:

Hopefully, the configure command finished without errors. Next up is to actually compile the thing. It’s the same command for both versions, and as you can see here I’ve appended -j4 to the command, which tells the compiler to run four jobs simultaneously to speed things up. I chose four jobs because I have a quad-core CPU ;)

Should the make fail with a gd lib error (most likely for PHP 5.3), you might want to try deleting a line in gd.c:

Search (Ctrl+W) for gdhelpers, and delete this line:

Then save the file and exit (Ctrl+O, Enter, Ctrl+X), and try the make command again.

Okay. Still here? Good :) Last step is to create the .deb package. You need to replace a lot of the options here to match your own data; email, date (for the version), and most importantly, the CPU architecture specified with the --arch parameter. I’m on a 64-bit Intel QuadCore, so my architecture is amd64. If you’re on a 32-bit architecture, you’d probably be specifying i386, i486 or i586. It could also be ia64 in case you’re on one of those Xeons. For PHP 5.3:

For PHP 6.0:

You might get an error message reading apxs:Error: At least one `LoadModule' directive already has to exist... If this happens, it’s because the Apache configuration file is empty. A quick workaround is to open up the configuration file:

and add these two lines:

Save and exit, then retry the checkinstall command.

Hopefully, by now, you’ll have a .deb package, ready to be installed. Try it out (replace the .deb name with the one you’ve just created):

Confirm the version:

If all is well you’ll see the right version. Working? I hope so :) If not, as promised, here are my packages (for regular 64-bit AMDs and Intels):


16 thoughts on “How to Create .deb Packages for PHP 5.3 and PHP 6.0”

  1. This just saved me a lot of trial-and-error, thanks. (-:

    I can’t wait for an “official” php5.3 package to be available, though: I just installed this alpha on a virtual machine to be able to develop a “nicer” version of my ActiveRecord-like class which depends on the “late static binding” feature, but I hope it won’t be too long before I’ll be able to use it in a production environment.

  2. Hey Void, thanks for that, especially considering that I’m probably not gonna be producing new ones, but just for the record, what are these “problems”?

  3. The How-to worked great also with PHP 5.3.0RC2. I compiled a .deb package for i686 which, after a reboot, works like a charm so far!

  4. The .configure bit failed with the apxs2 stuff, with I removed, then it failed regarding PCRE. I think I’ll wait for PHP 5.3 to be released, or install Gentoo on a Virtual machine.

  5. Thank you very much, this tutorial worked great for me. Now I can use namespaces, and all the other new features of PHP 5.3 under Ubuntu. :-)

    Greetings from Germany.

Leave a Reply