Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to setup the W3C fork of HTMLTidy (tidy-html5) as a PHP extension.

I had installed the normal php/tidy extension using the php5-tidy package.

I then downloaded the Git repository, and ran the following commands to compile the shared library:

sh build/gnuauto/ && ./configure && make
sudo make install

After restarting the php5-fpm service, I still see the same tidy information on phpinfo():

libTidy Release    25 March 2009
Extension Version  2.0 ($Id$)

Shouldn't the PHP extension start using tidy-html5 at this point? What can I do to make it work?

share|improve this question

One example how I use Tidy from within PHP:

$command = "tidy -indent -utf8 -xml -wrap 1000 data/cache/tidy-in.xml > data/cache/tidy-out.xml";
exec($command, $return, $code);
if ($code != 0) {
    throw new Exception(printf("Something went wrong: %s (%s)", join('<br />', $return), $code));
// the fixed version is here:
$html5 = file_get_contents('data/cache/tidy-out.xml');


$command = "tidy -version";
exec($command, $return, $code);
if (count($return) > 0) {
    // command line tidy available

you can test if you have a command line tidy available. Formerly the HTML5-compatible version from Github had HTML5 in the version text, now it just says 'HTML Tidy for Linux version 4.9.18' but I think that's enough to work with (for example if you want to differentiate between HTML5 compatible and basic tidy).

Another option:

if (extension_loaded("tidy")) {
    // the non-HTML5 php extension... maybe it serves you as fallback..
share|improve this answer

As I understand tidy-html5 is not a php module, so you can't use it directly with php. It's just a command line tools and/or shared library. You could try to build php with the new shared library

# configure ...
share|improve this answer
That's right, it's a shared library. Regarding the PHP configure command, how can I preserve existing configure options? I'm asking this because I installed PHP and all the other extensions using either apt or pecl and I'm not sure what kind of magic goes into play there. – Alix Axel Jul 3 '13 at 1:31

Unfortunately, I'm not ubuntu/debian expert (As I see you have used apt). On RHEL based system I just download and install, edit /root/rpmbuidl/SPESC/php53u.spec and rebuild rpm package

# rpmbuild -ba --target=x86_64 php53u.spec

As far as I know, on debian you can rebuild package too. Something like

$ sudo apt-get install devscripts build-essential fakeroot
$ apt-get source libapache2-mod-php5 php5-tidy
$ sudo apt-get build-dep libapache2-mod-php5
$ debuild -us -uc
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.