PHP 6 Installation Guide for Ubuntu 7.10 (Gutsy Gibbon)
It’s no longer news that next release of PHP is on it’s way. If you’re like me, you’re probably pretty keen to start experimenting with the new features, enhanced OO, and rejoice at the demise of ‘register_globals’. The only problem is: PHP 6 doesn’t have packaged releases just yet. In other words, if you want to start working with PHP 6, you need to compile it from source. To most Linux nuts, compiling source code is an everyday task. However if you’re not familiar with rolling your own binaries, the process can seem daunting, and with that in mind I decided to write a guide to compiling PHP 6.
Environment
I wrote this guide specifically for Ubuntu 7.10, and while most steps will work successfully for most flavors of Debian Linux, bear in mind that some commands and file system locations may need to change depending on the system you’re running. You’ll need administrative privileges to execute many of the steps described in this guide, so if your account isn’t already on the sudoers manifest, you might want to correct that first. I recommend using a virtual machine as a sandbox for experimental environments. This way, should anything go toes-up along the way, you won’t have damaged your regular working environment (VMWare server is free and does the job nicely).
Some Prerequsites
Before we can get started compiling PHP, there a few tools needed during the installation process that we’ll need to install first:
* libtool - GNU shared library manager
* bison - grammar parser
* flex - another source code parser
* re2c - lexical scanner
* g++ - GNU compiler collection (the c compiler)
* libxml2-dev - XMl libraries (a non-bundled dependency of PHP)
* autoconf - configures source code for compiling
* automake - used to build compiler instructions (’make’ files)
To install these packages, fire up a terminal window and enter:
sudo apt-get install libtool bison flex re2c g++ libxml2-dev autoconf automake
Once that’s done, you’ll have all the tools you need to compile ICU (International Components for Unicode) & then PHP 6.
Compiling and Installing ICU
One of the major features coming in PHP 6 is support for Unicode, and the ICU library is what provides unicode capability to PHP. To compile & install ICU, run the following commands in your terminal session:
mkdir ./icu_source cd icu_source wget ftp://ftp.software.ibm.com/software/globalization/icu/3.6/icu4c-3_6-src.tgz tar -xf ./icu4c-3_6-src.tgz cd icu/source sudo mkdir /usr/local/icu sudo ./configure --prefix=/usr/local/icu sudo make sudo make install
Install Apache
This step is optional, but if you’re like 99% of PHP developers (myself included), chances are you’ll want to use your PHP 6 install with Apache. Note that you need the non-threaded version of apache - because while PHP is not thread-safe, many of the PHP extension libraries are not. To install non-threaded Apache, run the following command:
sudo apt-get install apache2-mpm-prefork
Getting PHP 6 Source Code
The best place to get PHP 6 source code is from http://snaps.php.net/. The version I’m using in this guide was built on 17th of November 2007. Before carrying out these steps, you might want to check if a new version is available and use that instead. Here’s how to download & unpack the PHP 6 source code:
cd mkdir ./php_source cd ./php_source wget http://snaps.php.net/php6.0-200711170930.tar.bz2 tar -xf ./php6.0-200711170930.tar.bz2 cd ./php6.0-200711170930
PHP 6 Configuration
You need to configure your PHP build so the compiler knows which libraries and extensions you want supported. This is done using a configure script, like this (no need to use new lines, I’ve just done that to make the command easier to read):
sudo ./configure --prefix=/usr/local/php6 --enable-bcmath --enable-calendar --enable-dba --enable-exif --enable-ftp --enable-gd-native-ttf --enable-soap --enable-sqlite-utf8 --enable-wddx --with-apxs2=/usr/bin/apxs2 --with-gettext --with-iconv --with-openssl --with-pcre-regex --with-pdo-sqlite --with-sqlite --with-zlib --enable-zip
You don’t need to compile PHP 6 with support for *all* these libraries & extensions, however this is the default set of configuration options being used by the QA team doing the testing on PHP 6, hence this is also the configuration I’m recommending.
Heads-Up Apache Users!
Due to a quirk of apxs2 (the tool that builds and links the PHP executable module for apache), you’ll need to hack a commented-out dummy LoadModule directive into your httpd.conf. You can get more info on why this is necessary from (http://www.trachtenberg.com/blog/2004/08/25/apxs2-causes-php-install-to-barf-under-suse-91-and-apache-2/). It’s a shame apxs2 doesn’t have a nicer solution, but at least there’s a simple work-around. Open up you httpd.conf file in your favourite text editor (here, I’m using vim):
sudo vim /etc/apache2/httpd.conf
Add the following line, save and close the file:
#AddModule foo_module /usr/lib/apache2/modules/foo.so
The Crunch
Once the configure script has finished running (and you’ve put the dummy entry into httpd.conf), it’s time to compile the binaries (this process should look familiar from compiling & installing ICU). Just run the following commands.
sudo make sudo make install
Note that the steps above can take a while to run - usually about 10 to 15 minutes, depending on the specs of your computer.
PHP 6 is Now Yours!
If you’d like to run a quick check to test everything has gone according to plan, do this:
/usr/local/php6/bin/php --version
You should see something like the following:
PHP 6.0.0-dev (cli) (built: Nov 17 2007 22:57:15) Copyright (c) 1997-2007 The PHP Group Zend Engine v3.0.0-dev, Copyright (c) 1998-2007 Zend Technologies
Hooking Up With Apache
Lastly, if you want to use PHP 6 with Apache, you’ll need to configure the web server to use your swanky new PHP 6 binaries. First, add the configuration directives (again, I’m using vim here, but feel free to use whatever text editor you’re comfortable with):
sudo vim /etc/apache2/mods-available/php6.conf
Now add the following configuration section to the php6.conf file, save then close:
<IfModule mod_php6.c> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule>
Now you need to tell Apache where to find the PHP 6 module:
sudo vim /etc/apache2/mods-available/php6.load
Add the following line, then save and close the file.
LoadModule php6_module /usr/lib/apache2/modules/libphp6.so
At this point, it would probably be a good idea to remove the ‘hacked in’ LoadModule directive from /etc/apache2/htttpd.conf (See the section above called ‘Heads-up Apache Users’). It shouldn’t break anything if you don’t though. Apxs2 will have also added an additional LoadModule for php6 below the dummy entry - it’s safe to remove this as well, because we’ve just added the same thing to in the php6.load file.
Once you’ve finished editing the apache config files, enable the new module by running
sudo a2enmod php6
Finally, restart Apache so the configuration changes take affect:
sudo /etc/init.d/apache2 restart
If you knock together a quick script calling phpinfo(), you should now be seeing “PHP6.0.0-dev”!
Enjoy!
By the way: If you’re interested in hearing exactly what’s coming in PHP and you’re in Brisbane next week, come along to the Open Source Developers’ Conference, where I’ll be giving a presentation: “PHP 6 - What’s In, What’s Out and Why”
