Thursday, May 8, 2008

PHP Woes: Getting pspell to work

The pspell extension allows some language tools like spell checking and similar-word recommendations.

To get pspell working, Aspell is required. Aspell is an OpenSource spellchecker, that has become the preferred one, replacing pspell and Ispell. Only the name remains, pspell functions in PHP are waiting to be renamed to Aspell ones.

I'm listing out the following steps for a Windows-specific installation. This has nothing to do with the server you're using (IIS or Apache)


  1. Get the Windows port of Aspell from http://aspell.net/win32/ (v0.50.3 installer here)
  2. Alongside, download a language dictionary as well (English dictionary here)
  3. Install Aspell followed by the language dictionary

  4. Make aspell-15.dll and pspell-15.dll available to PHP by either
    • Adding your Aspell bin directory (C:/Program Files/Aspell/bin in my case) to system's PATH variable OR
    • Copying the files to your PHP folder (C:/PHP in my case), if your PHP folder is already listed in PATH variable OR
    • Copying the files to windows folder (C:/Windows/) or system folder (C:/Windows/System32/)

  5. Enable the pspell extension in your php.ini file
    • Open your php.ini (generally in the PHP root folder or in Windows folder)
    • Firstly, make sure you have pspell.dll in your extentions folder (configured by variable 'extension_dir' in php.ini)
    • scroll down to where your extensions are listed, and decomment (remove the semicolon) so it looks like extension=php_pspell.dll - doing so enables the extension
    • Parsing of the ini file is cranky on some systems, so make sure that the above line goes to top of other commented/disabled extentions.


  6. Restart your server. It reloads the PHP module, which in turn reads the ini file and loads respective extensions again.

  7. Test if working: Saving as little code as <?php $pspell = pspell_new('en'); ?> in a script, and executing the script should do it.