Rigidly defined areas of doubt and uncertainty.

Friday, June 16, 2006

HOWTO: Add libtidy support to PHP5 in Ubuntu.

Oddly, the default PHP5 package on Ubuntu doesn't have support for the HTML tidying library, libtidy (bug #41690). I followed the instructions in the Debian APT Howto and the Ubuntu Document Storage Facility and replaced the installed package with one I compiled myself from the source. On the off chance someone else finds it useful I've posted the steps I took here:

Create a directory for compiling the source code in.

$ mkdir source
$ mkdir source/php5
$ cd source/php5/

Get the source code package from the source repository. (Note you don't need root privileges for this step as you're not installing anything, just downloading the source to your personal directory).

$ apt-get source php5

Install the other packages needed by the source code to compile.

$ sudo apt-get build-dep php5

In the downloaded source code there is a file php5-5.1.2/debian/rules. Add --with-tidy to the end of the list of options in COMMON_CONFIG. Now compile the modified source.

$ cd php5-5.1.2
$ dpkg-buildpackage -rfakeroot -uc -b

and install the newly created packages.

$ cd ..
$ sudo dpkg -i *.deb

Apache is automatically restarted as part of the build process, and a quick check with phpinfo() shows the new compile date and lists the tidy module.

UPDATE
When the package manager next downloads the latest version of php5, your changes will be overwritten. So be careful what boxes you tick when it asks you what to update. To get the latest version with your changes added to it repeat the above process. Easy enough for a simple one line change, but for bigger changes you should create a diff file, or manage your version in svn.

3 comments:

Anonymous said...

Thanks Alex, for posting this on the off chance someone else finds it useful. I certainly did!

Alex Farran said...

Glad to help. I might just post a bit more often now.

Anonymous said...

Thanks Alex. I've followed these instructions twice now, since the update from php5-5.1.2-1ubuntu3.3 to php5-5.1.2-1ubuntu3.4 STILL did not implement --with-tidy in the compile, even though this is listed as an ubuntu bug! Very useful!