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
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_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,
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:
sudo apt-get install gcc automake make checkinstall libjpeg62-dev libpng12-dev apache2-prefork-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libxpm-dev libxft-dev libt1-dev libgd2-xpm-dev libgmp3-dev libsasl2-dev freetds-dev libmysqlclient15-dev unixodbc-dev libpspell-dev librecode-dev libsnmp-dev libsqlite0-dev libtidy-dev libxslt1-dev x11proto-core-dev libxau-dev libpthread-stubs0 libpthread-stubs0-dev libxdmcp-dev libxcb1-dev libxcb-xlib0-dev x11proto-input-dev x11proto-kb-dev xtrans-dev libx11-dev libxpm-dev libexpat1-dev libfreetype6-dev pkg-config libfontconfig1-dev apache2-mpm-prefork apache2-utils apache2.2-common comerr-dev libapr1 libapr1-dev libaprutil1 libaprutil1-dev libaspell-dev libct3 libdb4.6-dev libgmpxx4ldbl libice-dev libidn11-dev libkadm55 libkrb5-dev libldap2-dev libodbcinstq1c2 libpcre3-dev libpq-dev libsensors-dev libsm-dev libsnmp-perl libsqlite3-dev libssl-dev libsybdb5 libt1-5 libtidy-0.99-0 libwrap0-dev libxaw-headers libxaw7-dev libxext-dev libxmu-dev libxmu-headers libxrender-dev libxt-dev uuid-dev x11proto-render-dev x11proto-xext-dev libmcrypt4 libmcrypt-dev
If you want to build PHP 6, you’ll also need to get this:
sudo apt-get install libicu-dev
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:
wget http://snaps.php.net/php5.3-200810190830.tar.bz2 tar xvf php5.3-200810190830.tar.bz2 cd php5.3-200810190830
Or, for PHP 6:
wget http://snaps.php.net/php6.0-200810191230.tar.bz2 tar xvf php6.0-200810191230.tar.bz2 cd php6.0-200810191230
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:
./configure --prefix=/usr --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php5/apache2 --with-config-file-scan-dir=/etc/php5/apache2/conf.d --mandir=/usr/share/man --disable-debug --with-regex=php --disable-rpath --disable-static --with-pic --with-layout=GNU --with-pear=/usr/share/php --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-db4 --without-gdbm --with-iconv --enable-exif --enable-ftp --with-gettext --enable-mbstring --with-pcre-regex=/usr --enable-shmop --enable-sockets --enable-wddx --with-libxml-dir=/usr --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-exec-dir=/usr/lib/php5/libexec --without-mm --with-curl=shared,/usr --with-zlib-dir=/usr --with-gd=shared,/usr --enable-gd-native-ttf --with-gmp=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6 --with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-t1lib=shared,/usr --with-ldap=shared,/usr --with-ldap-sasl=/usr --with-mhash=shared,/usr --with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config --with-pspell=shared,/usr --with-unixODBC=shared,/usr --with-xsl=shared,/usr --with-snmp=shared,/usr --with-sqlite=shared,/usr --with-mssql=shared,/usr --with-tidy=shared,/usr --with-xmlrpc=shared --with-pgsql=shared,/usr --enable-gd-native-ttf --enable-dba=shared --with-openssl-dir=shared,/usr --enable-gd-jis-conv --enable-json --with-mcrypt=shared,/usr --enable-pcntl --with-pdo-mysql --with-pdo-odbc=unixODBC,/usr --with-pdo-pgsql=shared,/usr --with-pdo-sqlite --enable-xmlreader --with-tsrm-pthreads
Or, for PHP 6.0:
./configure --prefix=/usr --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php6/apache2 --with-config-file-scan-dir=/etc/php6/apache2/conf.d --mandir=/usr/share/man --disable-debug --with-regex=php --disable-rpath --disable-static --with-pic --with-layout=GNU --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-db4 --without-gdbm --with-iconv --enable-exif --enable-ftp --with-gettext --enable-mbstring --with-pcre-regex=/usr --enable-shmop --enable-sockets --enable-wddx --with-libxml-dir=/usr --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --libexecdir=/usr/lib/php6/libexec --without-mm --with-curl=shared,/usr --with-zlib-dir=/usr --with-gd --enable-gd-native-ttf --with-gmp=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6 --with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-t1lib=shared,/usr --with-ldap=shared,/usr --with-ldap-sasl=/usr --with-mhash=shared,/usr --with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config --with-pspell=shared,/usr --with-unixODBC=shared,/usr --with-xsl=shared,/usr --with-snmp=shared,/usr --with-sqlite=shared,/usr --enable-sqlite-utf8 --with-mssql=shared,/usr --with-tidy=shared,/usr --with-xmlrpc=shared --with-pgsql=shared,/usr --enable-gd-native-ttf --with-icu-dir=/usr --enable-dba=shared --with-openssl-dir=shared,/usr --enable-gd-jis-conv --enable-json --with-mcrypt=shared,/usr --enable-pcntl --with-pdo-mysql --with-pdo-odbc=unixODBC,/usr --with-pdo-pgsql=shared,/usr --with-pdo-sqlite --enable-xmlreader --with-tsrm-pthreads
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:
gdhelpers, and delete this line:
Then save the file and exit (
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
i586. It could also be
ia64 in case you’re on one of those Xeons. For PHP 5.3:
sudo checkinstall -D --install=no --fstrans=no --maintainer=your@email --reset-uids=yes --nodoc --pkgname=php5 --pkgversion=5.3-alpha3 --pkgrelease=200810190830 --arch=amd64
For PHP 6.0:
sudo checkinstall -D --install=no --fstrans=no --maintainer=your@email --reset-uids=yes --nodoc --pkgname=php6 --pkgversion=6.0.0-dev --pkgrelease=200810190830 --arch=amd64
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:
sudo nano /etc/apache2/httpd.conf
and add these two lines:
#LoadModule directive to aid module installations #LoadModule dummy_module /usr/lib/apache2/modules/mod_dummy.so
Save and exit, then retry the
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):
sudo dpkg -i php_5.3-alpha3-200810190830_amd64.deb
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):