Installing the W3C Markup Validator on Mac OS X

For web developers it is often convenient to have local access to a markup validator. There are browser extensions like the excellent HTML Validator extension, but sometimes you want a standalone installation that can be used for batch testing or other tasks where a browser extension isn’t the best solution.

Several (many) years ago I posted a Quicklink about a document on Apple’s Developer site called Installing the W3C HTML Validator on Mac OS X, which obviously is useful for those of us who use Mac OS X. That document is still online, but the instructions there don’t seem to be quite up-to-date. Instead of following them, here’s what I did to get the W3C Markup Validator running on Mac OS X 10.6.

Note: These instructions assume that you’re quite comfortable with using the Terminal to poke around under the hood of your Mac and that you know a bit about configuring Apache, running commands as root, etc. If that doesn’t sound like you I would advise against trying this.

  1. Install the Developer Tools if they aren’t already installed (Xcode.mpkg in the “Optional installs” folder on your Snow Leopard disc).
  2. Run Software Update to make sure everything is up-to-date.
  3. Install OpenSP as described in the W3C instructions.
  4. Install the required Perl modules by running install Bundle::W3C::Validator through CPAN. Sit back and wait, because it’s going to take a while.

    After plenty of downloading and compiling, the installation will most likely fail with the following message:

    Failed during this command:
     PETDANCE/HTML-Tidy-1.54.tar.gz               : make NO
     FLORA/perl-5.13.11.tar.gz                    : make NO isa perl

    Fortunately Tidy is an optional module, and the essential parts seem to be installed before this error, so it doesn’t appear to be a showstopper.

    I have no idea why the error occurs. I’ve tried installing this on at least three different Macs, including one with a completely clean install of OS X, and I get the same thing every time. It isn’t Mac OS X specific either – I get the same error on Ubuntu 10.10. If anyone knows what’s up with this and how to successfully install Bundle::W3C::Validator I’d appreciate if you would let me know.

  5. Download and unpack the validator according to the W3C instructions, but put it in /Library/WebServer/Documents/validator (or in ~/Sites/validator if you prefer) instead of in /usr/local/validator.
  6. Configure the validator. It should be enough to change the Base path in /etc/w3c/validator.conf to /Library/WebServer/Documents/validator (or wherever you put the validator files) instead of /usr/local/validator. Now calling the validator from the command line like this should work:

    /Library/WebServer/Documents/validator/cgi-bin/check uri=
  7. If you’re reading this you’ll most likely have Apache enabled already. In case you don’t, start it either by enabling Web Sharing in the sharing control panel or typing sudo apachectl start in the Terminal.
  8. In the directory where you unpacked the validator, find the file /httpd/conf/httpd.conf and copy it to the /etc/apache2/other/ directory.
  9. Edit the file, which should now be /etc/apache2/other/httpd.conf, to replace all occurrences of /usr/local/validator with /Library/WebServer/Documents/validator (or wherever you put the files).
  10. Save the file and restart Apache by entering sudo apachectl graceful.

With a bit of luck the validator should now be reachable at http://localhost/w3c-validator/.

To make it available at another URL, such as http://validator.local/ or whatever you prefer, you’ll need to set up a virtual host in Apache and edit your /etc/hosts file to add the name you want to use. I got this to work by copying the contents of /etc/apache2/other/httpd.conf inside a VirtualHost directive in /etc/apache2/users/username.conf and replacing all references to the /w3c-validator/ directory with /:

<VirtualHost *:80>
    ServerName validator.local
    DocumentRoot /Users/username/Sites/validator/htdocs

    # Stuff from /etc/apache2/other/httpd.conf
    AliasMatch ^/+check(/+referer)?$   /Users/username/Sites/validator/cgi-bin/check
    AliasMatch ^/+feedback(\.html)?$ /Users/username/Sites/validator/cgi-bin/

With that in place, remove /etc/apache2/other/httpd.conf and restart Apache again to make the changes take effect.

I’m posting this mostly as future reference for myself, but hopefully it will help others get the W3C Markup Validator up and running on Mac OS X as well.

Posted on May 4, 2011 in Productivity, Web Standards

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.