Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active March 20, 2022 22:45
Show Gist options
  • Select an option

  • Save magnetikonline/5965406 to your computer and use it in GitHub Desktop.

Select an option

Save magnetikonline/5965406 to your computer and use it in GitHub Desktop.
Building a W3C validator server under Ubuntu 12.04LTS server.

Building a W3C validator server under Ubuntu 12.04LTS

Note: Suggest using a 64bit version of Ubuntu 12.04LTS for the HTML5 validation component.

Steps from here: http://www.mattzuba.com/2011/03/install-w3c-markup-validation-service-on-ubuntu/

Install packages

$ sudo apt-get install \
	build-essential opensp libosp-dev \
	apache2-mpm-prefork libapache2-mod-perl2 \
	libxml-libxml-perl

Setup Perl

  • $ sudo perl -MCPAN -e shell

  • Accept the first yes prompt

  • Press enter to local::lib

  • Press enter to yes for selecting CPAN mirror

  • Note: things might crash out here back to shell, but it doesn't seem to matter, just re-run sudo perl -MCPAN -e shell and continue.

  • Now enter the following (will take some time to install - be patient):

      o conf prerequisites_policy follow
      install Bundle::W3C::Validator
      exit
    

Download validator source

$ mkdir ~/w3cvalidatorsrc && cd ~/w3cvalidatorsrc
$ wget http://validator.w3.org/validator.tar.gz
$ wget http://validator.w3.org/sgml-lib.tar.gz
$ tar xf validator.tar.gz
$ tar xf sgml-lib.tar.gz

Note:

  • ~/w3cvalidatorsrc/validator-1.3 is contents of validator.tar.gz
  • ~/w3cvalidatorsrc/validator-1.1 is contents of sgml-lib.tar.gz

Move source into place around filesystem

$ sudo mkdir -p /usr/local/validator
$ sudo mkdir -p /etc/w3c
$ cd validator-1.3
$ sudo mv htdocs share httpd/cgi-bin /usr/local/validator
$ sudo cp /usr/local/validator/htdocs/config/* /etc/w3c

Move sgml-lib from sgml-lib.tar.gz into place:

$ cd ../validator-1.1
$ mv htdocs/sgml-lib /usr/local/validator/htdocs
$ cd ..
$ sudo cp validator-1.3/httpd/conf/httpd.conf /etc/w3c
$ sudo ln -fs /etc/w3c/httpd.conf /etc/apache2/conf.d/w3c-validator.conf

Edit /etc/w3c/httpd.conf

  • $ sudo nano /etc/w3c/httpd.conf

  • Add following lines to <Directory> section (just inside opening block is fine):

      Order Allow,Deny
      Allow from all
    

Optional steps

Update /etc/w3c/httpd.conf so validator answers on the root of the virtual website - not under the /w3c-validator/ alias:

  • Change first two AliasMatch lines to:

      AliasMatch ^/+check(/+referer)?$ /usr/local/validator/cgi-bin/check
      AliasMatch ^/+feedback(\.html)?$ /usr/local/validator/cgi-bin/sendfeedback.pl
    
  • Change <LocationMatch> line to:

      <LocationMatch "^/+(check(/+referer)?|feedback(\.html)?)$">
    
  • Change Alias line to:

      Alias / /usr/local/validator/htdocs/
    
  • Change RewriteBase line to:

      RewriteBase /
    

Edit /etc/apache2/apache2.conf (optional)

May wish to trim back number of StartServers, MinSpareServers and MaxSpareServers servers in /etc/apache2/apache2.conf to help keep memory usage a little leaner:

<IfModule mpm_prefork_module>
	StartServers			1
	MinSpareServers			2
	MaxSpareServers			2
	MaxClients				150
	MaxRequestsPerChild		0
</IfModule>

Enable/disable Apache mod_* components

$ sudo a2enmod rewrite
$ sudo a2enmod expires
$ sudo a2enmod include
# Disable mod_perl - otherwise DTD checks will fail under certain validator requests
$ sudo a2dismod perl
$ sudo /etc/init.d/apache2 stop
$ sudo /etc/init.d/apache2 start

At this point you will be able to validate documents up to XHTML - but we want HTML5 validation (don't we?)...

Install Validator.nu for HTML5 document validation

Note: it seems installation of the Validator.nu HTML5 validator requires Ubuntu 64bit, I haven't been successful with building/running using a 32bit Ubuntu OS (stackoverflow errors).

$ sudo apt-get install git default-jdk
$ sudo su
$ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
$ mkdir ~/validator.nu && cd ~/validator.nu
$ git clone https://github.com/validator/validator.git build
# Note: the below build commands are run twice on purpose - this is not a typo, and expect to wait a long time for this to download/install
$ python build/build.py all
$ python build/build.py all
  • Validator.nu server will now be running on http://127.0.0.1:8888.
  • Ctrl-C to exit
  • Place html5validator.conf into /etc/init directory
  • $ sudo start html5validator
  • Now Validator.nu is running as a backgrounded daemon.

Some final tweaks required to w3c validator config to pass HTML5 documents onto the Validator.nu server:

  • $ sudo nano /etc/w3c/validator.conf

  • Uncomment last two lines to proxy HTML5 document w3c validator requests to Validator.nu:

     <External>
     ## Enable checking documents via external services.
     ## The example config below assumes that you have installed the validator.nu
     ## engine on the same machine as the markup validator.
     ## See http://about.validator.nu/ for installation instructions.
     HTML5 = http://localhost:8888/html5/
     CompoundXML = http://localhost:8888/
     </External>
    
  • Finally, restart apache web server:

     $ sudo /etc/init.d/apache2 stop
     $ sudo /etc/init.d/apache2 start

Update Validator.nu HTML5 validator

To update and re-build the Validator.nu server issue the following commands:

$ sudo su
$ stop html5validator
$ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
$ cd ~/validator.nu
$ python build/build.py all
$ start html5validator

All done!

The Validator should now should be present at either of the following URLs - depending if you did the optional /etc/w3c/httpd.conf modifications:

  • http://[serverIP]/w3c-validator/ or
  • http://[serverIP]/

Bonus points for VirtualBox

If runing the validator as a VM within VirtualBox you have the option of exposing the validator web server back to the host machine localhost on an alternative port via VirtualBox's port forwarding feature.

Firstly, make the following edits to /etc/apache2/ports.conf so Apache2 listens on 0.0.0.0:80:

#NameVirtualHost 0.0.0.0:80
ServerName localhost
Listen 0.0.0.0:80

Restart Apache2:

$ sudo /etc/init.d/apache2 stop
$ sudo /etc/init.d/apache2 start

Now open settings for the VirtualBox instance:

  • Goto Network
  • Ensure Adapter 1 is set to NAT
  • Open Advanced and click Port Forwarding
  • Add a new entry:
    • Protocol: TCP
    • Host IP: 127.0.0.1
    • Host Port: 5000 (or another random unused port)
    • Guest IP: 0.0.0.0
    • Guest Port: 80

With this set you should now have the validator listening on http://localhost:5000/.

description "Validator.nu HTML5 Validator"
start on (local-filesystems and net-device-up)
stop on runlevel [016]
chdir /root/validator.nu
exec python build/build.py --control-port=8889 run
respawn
#!/bin/bash
stop html5validator
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
cd ~/validator.nu
python build/build.py all
start html5validator
@dnaber-de
Copy link
Copy Markdown

I think there's a typo here:

$ git clone https://github.com/validator/build.git build

Shouldn't it be https://github.com/validator/validator.git?

@magnetikonline
Copy link
Copy Markdown
Author

Thanks @dnaber-de - blame lack of Gist notifications to email (which now work!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment