Fixing PCRE_UTF8 Errors in FreeBSD

I have recently encountered this error:
PHP Warning: preg_match(): Compilation failed: this version of PCRE is not compiled with PCRE_UTF8 support at offset 0

And despite some of the suggested solutions I have found in various Drupal and MediaWiki forums, all of them related to older versions of ports.
The version of pcre I have installed is 7.8. as seen here:

PCRE version 7.8 2008-09-05
Compiled with
  UTF-8 support
  Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

But the curious thing is phpinfo(), told a different story.

Why was phpinfo() telling me the version of pcre was 5.0.13?
I checked various things like which libraries php was linked to, and sure enough it was in fact the libpcre that it should have been. After countless iterations of “let me tweak this Makefile and see if it makes a difference” and countless rebuilds of pcre and php, it occurred me, what about Apache? Now I’m not really sure why I this occurred to me, or why it did not occur to me earlier, perhaps it was a result of having felt I had already exhausted the rest of my options.

So I took a look at the Apache build config:

# cd /usr/ports/www/apache22
# make config

Apparently the pcre Apache is using is a bundled one, so I decided to change this to use devel/pcre, where I know UTF-8 support is enabled.

and proceeded to rebuild and reinstall the apache22 port.
After restarting apache, my first test was to inspect what phpinfo() was reporting.

Now phpinfo is agreeing with what I originally expected it to, the pcre port that is installed. I proceeded to test my php code with great success and have not seen the error since.

I encountered this on FreeBSD 7.0 , Apache 2.2.9, PHP 5.2.7, and pcre 7.8. But given the large number of seemingly unresolved threads I’ve encountered through google I expect that there are similar situations in other operating systems and software versions as well.

12 thoughts on “Fixing PCRE_UTF8 Errors in FreeBSD”

  1. it seems like this is now fixed in the apache22 port. I encountered the same problem and simply upgraded from 2.2.9 to 2.2.11 and it now uses the system PCRE lib. A “make config” does not show any pcre options anymore.

  2. Mark, I have tried this and it is still failing for me. 🙁

    I have rebuilding www/apache22, devel/pcre and devel/php5-pcre

    any ideas on how to get this working again?

  3. I couldn’t believe you, but it worked!

    Rebuilding Apache caused a jump in the PCRE version reported by phpinfo() from “5.0 13-Sep-2004” to the pcre port’s version.

    So apparently PHP is using the pcre bundled by apache.

    I might add that nowadays, the port maintainer has fixed this issue. Apache 2.2.11 no longer has the config option to use its own PCRE, but always uses the system version. 🙂

  4. On a FreeBSD 8.1 system with a current ports tree, I just could not get the Apache port to use the locally-installed PCRE libraries and headers, even when I added “–with-pcre=/usr/local” to the Makefile configuration option set. I finally wound up deinstalling that Apache, downloading an Apache tarball from, and installing that, adding “with-pcre=/usr/local“. That ended a week of frustrated fiddling with the options in the Apache and PHP ports.

    That worked for me, and I post my experience here in case it benefits someone else.

  5. Severity: Warning

    Message: preg_match(): Compilation failed: this version of PCRE is not compiled with PCRE_UTF8 support at offset 0

    i face this type of problem . whats is the problem can u explain me???

Leave a Reply

Your email address will not be published. Required fields are marked *