OS X hosting, Xserves, Mac Minis, G4’s, G5s

Here for all your hosting and support.

W3C HTML Validator on OS X

leave a comment »

Installing the W3C HTML Validator on Mac OS X

Building a website is a complicated process, and testing your finished product on every possible browser can be even more daunting. However, because modern browsers such as Safari, Mozilla, and Internet Explorer 6 are compliant with the World Wide Web Consortium’s (W3C) standards, testing your pages with the W3C Validation Tool is a great way to ensure that your pages work with modern browsers. The W3C Validator provides a line-by-line level of feedback, such as error information with references to the standards, on any URL you submit or HTML file you upload.

But what if your pages are accessible only within your firewall? Or what if your organization is reluctant to have their pages submitted to any external site for validation—even if it’s fully automated? This article describes how you can host the same W3C standards validation service within the confines of your own network and security constraints. You just need to download a number of open-source components that are freely available, and then configure them properly. By following this recipe, you will have an internal validation tool that will not only be accessible to your web developers as needed, but can actually be integrated into your production process. You have the code—you can make it fit your workflow.

Validator Files

First be sure to have the Xcode Tools 1.5 or higher installed.

Besides the Xcode Tools, you need to download the validator and supporting files:
Base Code: http://validator.w3.org/validator.tar.gz
DTD Library: http://validator.w3.org/sgml-lib.tar.gz

Once you download these files, you need to decompress them, move them to the proper location, and set the permissions for the executable file. The above downloaded files will download to your downloads folder, ours was on the Desktop, as shown below. Do this in the Terminal Window. The following is an example of where to move the files to (assuming they were downloaded to your desktop).

Welcome to Darwin!
macosx:~ macosx$ cd Desktop
macosx:~/Desktop macosx$ tar xf validator.tar
macosx:~/Desktop macosx$ tar xf sgml-lib.tar
macosx:~ macosx$ cd /Library/WebServer/Documents
macosx:/Library/WebServer/Documents/ macosx$ mkdir validator/
macosx:/Library/WebServer/Documents/ macosx$ cp -R ~/Desktop/validator-0.7.0/ validator/
macosx:/Library/WebServer/Documents/ macosx$ cd validator/htdocs/
macosx:/Library/WebServer/Documents/validator/htdocs macosx$ cp ../httpd/cgi-bin/check .
macosx:/Library/WebServer/Documents/validator/htdocs macosx$ sudo chmod 755 check

Edit the validator.conf file

Now, edit the validator.conf file (located at /Library/WebServer/Documents/validator/htdocs/config/validator.conf) with your favorite text editor. Do not cut and paste from the example file below, this will create an invalid config file.

  1. Change the ‘Maintainer’ email address on line 73 to your email address.
  2. Change the ‘Home Page’ URL on line 77 to the correct URL for your installation.
  3. Uncomment & change the base path of ‘/usr/local/validator’ to ‘/Library/WebServer/Documents/validator’ on line 24.
  4. Change ‘SGML Parser’ from ‘/usr/bin/onsgmls’ to ‘/sw/bin/onsgmls’ on line 37, this is where Fink will install the OpenSP software later in these instructions.
  5. Save the file.

Here is what our file looked like when we finished:

# Main Configuration File for the W3C Markup Validation Service.
# $Id: validator.conf,v 1.24 2005/07/08 08:31:09 ot Exp $
# See 'perldoc Config::General' for the syntax, and be aware that the
# 'SplitPolicy' is 'equalsign', ie. keys and values are separated by '\s*=\s*',
# and that 'InterPolateVars' is in effect.

# Base Path for Markup Validator files.
# You MUST set these unless you use the default locations for the files.
# e.g. the config files in "/etc/w3c/" and everything else in
# "/usr/local/validator/".
# Make sure all file paths below do NOT end with a slash

  # Base path.  Defaults to the value of the W3C_VALIDATOR_HOME environment
  # variable or /usr/local/validator if the variable does not exist.
  Base = /Library/WebServer/Documents/validator

  # Location of template files
  Templates = $Base/share/templates

    # The SGML Library Path.
    Library = $Base/htdocs/sgml-lib

    # The SGML Parser to use.  Defaults to /usr/bin/onsgmls.
    Parser = /sw/bin/onsgmls

# This controls whether the debugging options are allowed to be enabled.
Allow Debug = yes

# This lets you permanently enable the debugging options. Can be overridden
# with CGI options (unlike "Allow Debug" above).
Enable Debug = no

# Whether private RFC1918 addresses are allowed.
Allow Private IPs = no

# Whether the (highly experimental!) SOAP support should be enabled.
Enable SOAP = no

# Whether the validator will check its own output.
# 0 means it will refuse to check its own output, 1 means it will but it will
# refuse to check the results of it checking itself. Etc.
Max Recursion = 0

# Protocols the validator is allowed to use for retrieving documents.
# The default is to allow http and https.
  Allow = data,http,https

# Email address of the maintainer of this service.
Maintainer = web-dev@lists.apple.com

# The "Home Page" for the service.  Make sure this ends with a slash.
Home Page = http://localhost/validator/htdocs/

# Base URI for the Element Reference.
Element Ref URI = http://www.htmlhelp.com/reference/html40/

# Mapping tables etc...

# Maps element names to URLs (cf. "Element Ref URI" above).
  Include eref.cfg

# Main document Type Registry; contains all information on the types
# of documents we support and how they are processed.
  Include types.conf

# Mapping of charset names to their IANA names and how iconv(3) knows them.
  Include charset.cfg

# Map MIME Media Type to Parse Mode mapping.
  text/xml              = XML
  image/svg             = XML
  image/svg+xml         = XML
  application/smil      = XML
  application/xml       = XML
  text/html             = TBD
  text/vnd.wap.wml      = XML
  application/xhtml+xml = XML
  application/mathml+xml = XML

# Source for the "Tip of The Day" blurbs.
  Include tips.cfg

Once you have edited this file, you need to move it to the proper location. Again, do this in the Terminal Window, as shown below.

Welcome to Darwin!
macosx:~ macosx$  cd /etc
macosx:/etc macosx$ sudo mkdir w3c
macosx:/etc macosx$ cd w3c
macosx:/etc/w3c macosx$ sudo cp /Library/WebServer/Documents/validator/htdocs/config/*.* .

Edit the apache httpd.conf file

Now, edit the apache config file—this example uses the application pico—to tell apache some information about the validator; we again use the Terminal Window for this:

Welcome to Darwin!
macosx:~ macosx$ sudo pico /etc/httpd/httpd.conf

This opens the apache config file into the pico text editor. Scroll to the bottom of the file and add the following lines:

# This is the directory where you have the validator's "check"
# script as well as its and *.html, *.css etc files.

<Directory /Library/WebServer/Documents/validator/htdocs>
  Options              ExecCGI IncludesNOEXEC Indexes MultiViews
  AllowOverride        None
  AddHandler           server-parsed .html
  AddCharset           utf-8         .html

# Tell httpd that "check" is a CGI script.

<Location "/validator/htdocs/check">
  SetHandler           cgi-script

Save the file by pressing Control-X and answering ‘Y’ to the prompt.

Now, restart personal web sharing from the Terminal Window:

Welcome to Darwin!
macosx:~ macosx$ sudo apachectl graceful

Install Fink & OpenSP

Install Open SP (this is needed in order for the validator to run). The easiest way to install Open SP is via Fink. Follow the Fink Installation Instructions for Mac OS X if you don’t already have Fink installed.

Once you have completed a full Fink installation and Fink selfupdate, then install OpenSP via Fink, using the Terminal Window:

Welcome to Darwin!
macosx:~ macosx$ Fink install openSP3

Installing the Necessary Perl Modules

The easiest way to install the required Perl modules is via CPAN. The W3C has provided a CPAN bundle that will install all the required Perl modules. If this is the first time you are using CPAN, you must first go through a configuration of CPAN. All the default answers to the prompts should be sufficient—just press the Return key at each prompt.

Open the Terminal Window and run CPAN:

Welcome to Darwin!
macosx:~ macosx$ sudo perl -MCPAN -e shell

After configuring CPAN, you get a cpan> command prompt. Now you are ready to install the bundle via CPAN as shown below. You will need to accept ‘recursively get missing modules’

cpan> install Bundle::W3C::Validator


Your validator should now be working now at http://localhost/validator/htdocs/ on your local Mac.

If you have any questions or comments, you can post to the Apple Web Development Mailing List.

This article was tested on Mac OS X (10.4). The original panther tested version of this article is located at http://developer.apple.com/internet/opensource/validatorpanther.html


Written by montanaflynn

January 30, 2008 at 6:06 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: